1
|
import javax.servlet.*;
|
2
|
import javax.servlet.http.*;
|
3
|
import java.io.*;
|
4
|
import java.util.Hashtable;
|
5
|
|
6
|
import edu.ucsb.nceas.metacat.*;
|
7
|
|
8
|
public class Upload999 extends HttpServlet
|
9
|
{
|
10
|
public void service(ServletRequest request, ServletResponse response)
|
11
|
throws IOException
|
12
|
{
|
13
|
PrintWriter out = null;
|
14
|
try {
|
15
|
int id=0;
|
16
|
|
17
|
out = response.getWriter();
|
18
|
|
19
|
String file = new String("");
|
20
|
DBConnection dbconn = null;
|
21
|
|
22
|
MultipartParser parser = new MultipartParser((HttpServletRequest)request, 1024 * 1024);
|
23
|
Part aPart;
|
24
|
String eml_filename=" ",docid=" ";
|
25
|
Hashtable formElements = new Hashtable();
|
26
|
while( (aPart = parser.readNextPart()) != null ) {
|
27
|
if( aPart.isParam() == true ) {
|
28
|
ParamPart pPart = (ParamPart)aPart;
|
29
|
String field = pPart.getName();
|
30
|
String value = pPart.getStringValue();
|
31
|
if(field != null) {
|
32
|
if(value == null)
|
33
|
value = "";
|
34
|
formElements.put(field, value);
|
35
|
docid=value;
|
36
|
}
|
37
|
}
|
38
|
else if( aPart.isFile() == true ) {
|
39
|
FilePart fPart = (FilePart)aPart;
|
40
|
String field = fPart.getName();
|
41
|
String fileName = fPart.getFileName();
|
42
|
if(fileName != null) {
|
43
|
//write the image to a file
|
44
|
String dir = "/tmp/Upload_data";
|
45
|
File theFile = new File(dir, fileName);
|
46
|
fPart.writeTo(theFile);
|
47
|
eml_filename = dir+"/"+fileName;
|
48
|
formElements.put(field, fileName);
|
49
|
}
|
50
|
}
|
51
|
}
|
52
|
// out.println( formElements );
|
53
|
out.println( docid + " " + eml_filename );
|
54
|
out.println("EML File uploaded");
|
55
|
/*****************************************************/
|
56
|
/* Change for input to metacat */
|
57
|
|
58
|
dbconn=DBConnectionPool.getDBConnection("DocumentImpl.main");
|
59
|
|
60
|
|
61
|
String newdocid = DocumentImpl.write(dbconn, eml_filename, null,
|
62
|
"null", "INSERT", docid,
|
63
|
null, null);
|
64
|
|
65
|
if ((docid != null) && (!docid.equals(newdocid))) {
|
66
|
|
67
|
System.out.println("New document ID generated!!! ");
|
68
|
}
|
69
|
|
70
|
|
71
|
/****************************************************/
|
72
|
|
73
|
|
74
|
} catch (Exception e) {
|
75
|
out.println("An error occurred.");
|
76
|
e.printStackTrace(out);
|
77
|
}
|
78
|
|
79
|
out.flush();
|
80
|
}
|
81
|
}
|