1 |
298
|
berkley
|
/**
|
2 |
|
|
* '$RCSfile$'
|
3 |
|
|
* Purpose: class that implements the MARINE interface to the
|
4 |
|
|
* metadata database.
|
5 |
|
|
* Copyright: 2000 Regents of the University of California and the
|
6 |
|
|
* National Center for Ecological Analysis and Synthesis
|
7 |
|
|
* Authors: Chad Berkley
|
8 |
|
|
*
|
9 |
385
|
berkley
|
* '$Author$'
|
10 |
298
|
berkley
|
* '$Date$'
|
11 |
|
|
* '$Revision$'
|
12 |
|
|
*/
|
13 |
|
|
|
14 |
295
|
berkley
|
package edu.ucsb.nceas.metacat.marine;
|
15 |
|
|
|
16 |
|
|
import java.io.*;
|
17 |
|
|
import java.util.*;
|
18 |
|
|
import javax.servlet.*;
|
19 |
|
|
import javax.servlet.http.*;
|
20 |
|
|
import java.net.*;
|
21 |
|
|
import java.sql.*;
|
22 |
|
|
import org.xml.sax.*;
|
23 |
|
|
import org.xml.sax.helpers.*;
|
24 |
298
|
berkley
|
import edu.ucsb.nceas.metacat.*;
|
25 |
295
|
berkley
|
import oracle.jdbc.driver.*;
|
26 |
|
|
import oracle.xml.parser.v2.*;
|
27 |
|
|
import oracle.xml.parser.v2.XMLParser;
|
28 |
|
|
|
29 |
376
|
berkley
|
public class marineServlet extends edu.ucsb.nceas.metacat.MetaCatServlet
|
30 |
|
|
{
|
31 |
385
|
berkley
|
MetaCatUtil util = new MetaCatUtil();
|
32 |
|
|
|
33 |
376
|
berkley
|
/**
|
34 |
|
|
* Transorms an xml resultset document to html and sends it to the browser
|
35 |
|
|
* @param resultdoc the string representation of the document that needs
|
36 |
|
|
* to be transformed.
|
37 |
|
|
* @param response the HttpServletResponse object bound to the client.
|
38 |
|
|
* @param out the output stream to the client
|
39 |
|
|
*/
|
40 |
|
|
protected void transformResultset(String resultdoc,
|
41 |
|
|
HttpServletResponse response,
|
42 |
|
|
PrintWriter out)
|
43 |
|
|
{
|
44 |
|
|
Connection conn = null;
|
45 |
|
|
try
|
46 |
|
|
{
|
47 |
|
|
conn = util.getConnection();
|
48 |
|
|
DBTransform trans = new DBTransform(conn);
|
49 |
|
|
response.setContentType("text/html");
|
50 |
|
|
trans.transformXMLDocument(resultdoc, "-//NCEAS//marineresultset//EN",
|
51 |
|
|
"-//W3C//HTML//EN", out);
|
52 |
385
|
berkley
|
util.returnConnection(conn);
|
53 |
|
|
util.closeConnections();
|
54 |
376
|
berkley
|
}
|
55 |
|
|
catch(Exception e)
|
56 |
|
|
{
|
57 |
385
|
berkley
|
out.println("error: " + e.getMessage());
|
58 |
|
|
//if (conn != null)
|
59 |
376
|
berkley
|
{
|
60 |
385
|
berkley
|
util.returnConnection(conn);
|
61 |
|
|
util.closeConnections();
|
62 |
376
|
berkley
|
}
|
63 |
|
|
}
|
64 |
|
|
}
|
65 |
|
|
|
66 |
385
|
berkley
|
/**
|
67 |
|
|
* Formats the text in the <query> tag so that the tag name is the name
|
68 |
|
|
* of the field and the content is the query itself. This is used to
|
69 |
|
|
* fill in the text boxes in the xsl created html form.
|
70 |
|
|
*
|
71 |
|
|
* @param param is the query parameters from the CGI
|
72 |
|
|
*/
|
73 |
|
|
protected String transformQuery(Hashtable params)
|
74 |
|
|
{
|
75 |
|
|
StringBuffer query = new StringBuffer();
|
76 |
|
|
Object nextkey = null;
|
77 |
|
|
Object nextelement = null;
|
78 |
|
|
|
79 |
|
|
Enumeration elements = params.elements();
|
80 |
|
|
Enumeration keys = params.keys();
|
81 |
|
|
while(keys.hasMoreElements() && elements.hasMoreElements())
|
82 |
|
|
{
|
83 |
|
|
nextkey = keys.nextElement();
|
84 |
|
|
nextelement = elements.nextElement();
|
85 |
|
|
//allow for more than value per field name
|
86 |
|
|
for(int i=0; i<((String[])nextelement).length; i++)
|
87 |
|
|
{
|
88 |
|
|
if(((String[])nextelement).length > 1)
|
89 |
|
|
{ //this allows multiple values to be returned if there is more than
|
90 |
|
|
//one of this field in the query.
|
91 |
|
|
//(String)nextkey += String.valueOf(i);
|
92 |
|
|
}
|
93 |
|
|
query.append("<").append((String)nextkey).append(">");
|
94 |
|
|
if(!((String[])nextelement)[i].equals(""))
|
95 |
|
|
{
|
96 |
|
|
query.append(((String[])nextelement)[i]);
|
97 |
|
|
}
|
98 |
|
|
query.append("</").append((String)nextkey).append(">");
|
99 |
|
|
}
|
100 |
|
|
}
|
101 |
|
|
return query.toString();
|
102 |
|
|
}
|
103 |
376
|
berkley
|
}
|
104 |
385
|
berkley
|
|
105 |
|
|
|
106 |
|
|
|
107 |
|
|
|
108 |
|
|
|
109 |
|
|
|
110 |
|
|
|
111 |
|
|
|
112 |
|
|
|
113 |
|
|
|
114 |
|
|
|
115 |
|
|
|
116 |
|
|
|
117 |
|
|
|
118 |
|
|
|
119 |
|
|
|
120 |
|
|
|
121 |
|
|
|
122 |
|
|
|
123 |
|
|
|
124 |
|
|
|