Revision 55
Added by Matt Jones about 24 years ago
MetaCatServlet.java | ||
---|---|---|
19 | 19 |
import java.net.URL; |
20 | 20 |
import java.net.MalformedURLException; |
21 | 21 |
import java.sql.Connection; |
22 |
import java.sql.SQLException; |
|
22 | 23 |
|
23 | 24 |
import javax.servlet.ServletConfig; |
24 | 25 |
import javax.servlet.ServletContext; |
... | ... | |
50 | 51 |
|
51 | 52 |
private ServletConfig config = null; |
52 | 53 |
private ServletContext context = null; |
54 |
Connection conn = null; |
|
53 | 55 |
DBSimpleQuery queryobj = null; |
54 | 56 |
DBReader docreader = null; |
55 | 57 |
static String user = MetaCatUtil.user; |
... | ... | |
68 | 70 |
|
69 | 71 |
try { |
70 | 72 |
// Open a connection to the database |
71 |
Connection dbconn = MetaCatUtil.openDBConnection(
|
|
73 |
conn = MetaCatUtil.openDBConnection( |
|
72 | 74 |
"oracle.jdbc.driver.OracleDriver", |
73 | 75 |
defaultDB, user, password); |
74 | 76 |
|
75 |
queryobj = new DBSimpleQuery(dbconn);
|
|
76 |
docreader = new DBReader(dbconn);
|
|
77 |
queryobj = new DBSimpleQuery(conn); |
|
78 |
docreader = new DBReader(conn); |
|
77 | 79 |
} catch (Exception e) { |
78 | 80 |
} |
79 | 81 |
} catch ( ServletException ex ) { |
... | ... | |
123 | 125 |
handleQueryAction(out, params, response); |
124 | 126 |
} else if (action.equals("getdocument")) { |
125 | 127 |
handleGetDocumentAction(out, params, response); |
128 |
} else if (action.equals("putdocument")) { |
|
129 |
handlePutDocumentAction(out, params, response); |
|
126 | 130 |
} else { |
127 | 131 |
out.println("Error: action not registered. Please report this error."); |
128 | 132 |
} |
... | ... | |
192 | 196 |
|
193 | 197 |
out.println(doc); |
194 | 198 |
} |
199 |
|
|
200 |
/** |
|
201 |
* Handle the database putdocument request and write an XML document |
|
202 |
* to the database connection |
|
203 |
*/ |
|
204 |
private void handlePutDocumentAction(PrintWriter out, Hashtable params, |
|
205 |
HttpServletResponse response) { |
|
206 |
// Get the document indicated |
|
207 |
String doctext = ((String[])params.get("doctext"))[0]; |
|
208 |
StringReader xml = new StringReader(doctext); |
|
209 |
try { |
|
210 |
DBSAXWriter dbw = new DBSAXWriter(doctext, conn); |
|
211 |
} catch (SQLException e1) { |
|
212 |
out.println("Error loading document:<p>\n" + e1.getMessage()); |
|
213 |
}catch (IOException e2) { |
|
214 |
out.println("Error loading document:<p>\n" + e2.getMessage()); |
|
215 |
}catch (ClassNotFoundException e3) { |
|
216 |
out.println("Error loading document:<p>\n" + e3.getMessage()); |
|
217 |
} |
|
218 |
//String doc = docreader.readXMLDocument((new Long(docid)).longValue()); |
|
219 |
|
|
220 |
// set content type and other response header fields first |
|
221 |
response.setContentType("text/html"); |
|
222 |
|
|
223 |
out.println("Finished loading document."); |
|
224 |
} |
|
195 | 225 |
} |
Also available in: Unified diff
added xml doc loading to servlet actions