Revision 385
Added by berkley over 24 years ago
src/edu/ucsb/nceas/metacat/marine/marineServlet.java | ||
---|---|---|
6 | 6 |
* National Center for Ecological Analysis and Synthesis |
7 | 7 |
* Authors: Chad Berkley |
8 | 8 |
* |
9 |
* '$Author$' |
|
9 |
* '$Author$'
|
|
10 | 10 |
* '$Date$' |
11 | 11 |
* '$Revision$' |
12 | 12 |
*/ |
... | ... | |
28 | 28 |
|
29 | 29 |
public class marineServlet extends edu.ucsb.nceas.metacat.MetaCatServlet |
30 | 30 |
{ |
31 |
MetaCatUtil util = new MetaCatUtil(); |
|
32 |
|
|
31 | 33 |
/** |
32 | 34 |
* Transorms an xml resultset document to html and sends it to the browser |
33 | 35 |
* @param resultdoc the string representation of the document that needs |
... | ... | |
39 | 41 |
HttpServletResponse response, |
40 | 42 |
PrintWriter out) |
41 | 43 |
{ |
42 |
MetaCatUtil util = new MetaCatUtil(); |
|
43 | 44 |
Connection conn = null; |
44 | 45 |
try |
45 | 46 |
{ |
... | ... | |
48 | 49 |
response.setContentType("text/html"); |
49 | 50 |
trans.transformXMLDocument(resultdoc, "-//NCEAS//marineresultset//EN", |
50 | 51 |
"-//W3C//HTML//EN", out); |
52 |
util.returnConnection(conn); |
|
53 |
util.closeConnections(); |
|
51 | 54 |
} |
52 | 55 |
catch(Exception e) |
53 | 56 |
{ |
54 |
if (conn != null) |
|
57 |
out.println("error: " + e.getMessage()); |
|
58 |
//if (conn != null) |
|
55 | 59 |
{ |
56 |
util.returnConnection(conn); |
|
60 |
util.returnConnection(conn); |
|
61 |
util.closeConnections(); |
|
57 | 62 |
} |
58 | 63 |
} |
59 | 64 |
} |
60 | 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 |
System.out.println(query.toString()); |
|
102 |
return query.toString(); |
|
103 |
} |
|
61 | 104 |
} |
105 |
|
|
106 |
|
|
107 |
|
|
108 |
|
|
109 |
|
|
110 |
|
|
111 |
|
|
112 |
|
|
113 |
|
|
114 |
|
|
115 |
|
|
116 |
|
|
117 |
|
|
118 |
|
|
119 |
|
|
120 |
|
|
121 |
|
|
122 |
|
|
123 |
|
|
124 |
|
|
125 |
|
|
126 |
|
Also available in: Unified diff
marineServlet now overrides the transformQuery() function to allow it to put the values back into the text boxes of the xsl stylesheet rendered form.