Revision 897
Added by berkley almost 23 years ago
src/edu/ucsb/nceas/metacat/marine/marineServlet.java | ||
---|---|---|
1 |
/** |
|
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 |
* '$Author$' |
|
10 |
* '$Date$' |
|
11 |
* '$Revision$' |
|
12 |
*/ |
|
13 |
|
|
14 |
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 |
import edu.ucsb.nceas.metacat.*; |
|
25 |
import oracle.jdbc.driver.*; |
|
26 |
import oracle.xml.parser.v2.*; |
|
27 |
import oracle.xml.parser.v2.XMLParser; |
|
28 |
|
|
29 |
public class marineServlet extends edu.ucsb.nceas.metacat.MetaCatServlet |
|
30 |
{ |
|
31 |
MetaCatUtil util = new MetaCatUtil(); |
|
32 |
|
|
33 |
/** |
|
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", null, out); |
|
52 |
util.returnConnection(conn); |
|
53 |
util.closeConnections(); |
|
54 |
} |
|
55 |
catch(Exception e) |
|
56 |
{ |
|
57 |
out.println("error: " + e.getMessage()); |
|
58 |
//if (conn != null) |
|
59 |
{ |
|
60 |
util.returnConnection(conn); |
|
61 |
util.closeConnections(); |
|
62 |
} |
|
63 |
} |
|
64 |
} |
|
65 |
|
|
66 |
/** |
|
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 |
|
|
104 |
/** |
|
105 |
* decodes the mouse click information coming from the client. |
|
106 |
* @param params the parameters from the CGI |
|
107 |
* @return action the action to be performed or "error" if an error was |
|
108 |
* generated |
|
109 |
*/ |
|
110 |
protected String decodeMouseAction(Hashtable params) |
|
111 |
{ |
|
112 |
// Determine what type of request the user made |
|
113 |
// if the action parameter is set, use it as a default |
|
114 |
// but if the ypos param is set, calculate the action needed |
|
115 |
String action=null; |
|
116 |
long ypos = 0; |
|
117 |
try { |
|
118 |
ypos = (new Long(((String[])params.get("ypos"))[0]).longValue()); |
|
119 |
//System.out.println("<P>YPOS IS " + ypos); |
|
120 |
if (ypos <= 13) { |
|
121 |
action = "getabstract"; |
|
122 |
} else if (ypos > 13 && ypos <= 25) { |
|
123 |
action = "getdocument"; |
|
124 |
} else if (ypos > 25) { |
|
125 |
action = "getdatadoc"; |
|
126 |
} |
|
127 |
return action; |
|
128 |
} catch (Exception npe) { |
|
129 |
// |
|
130 |
// MBJ -- NOTE that this should be handled more gracefully with |
|
131 |
// the new exception infrastructure -- this "error" return |
|
132 |
// value is inappropriate |
|
133 |
//out.println("<P>Caught exception looking for Y value."); |
|
134 |
return "error"; |
|
135 |
} |
|
136 |
} |
|
137 |
} |
|
138 |
|
|
139 | 0 |
Also available in: Unified diff
removed because this is no longer used. it was causing a compile error when using postgres because it directly imports the oracle driver.