1 |
1734
|
skrish
|
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 |
|
|
}
|