Revision 566
Added by Matt Jones over 23 years ago
MetaCatUtil.java | ||
---|---|---|
228 | 228 |
} |
229 | 229 |
|
230 | 230 |
/** |
231 |
* Utility method to parse the query part of a URL into parameters. This |
|
232 |
* method assumes the format of the query par tof the url is an |
|
233 |
* ampersand separated list of name/value pairs, with equal signs separating |
|
234 |
* the name from the value (e.g., name=tom&zip=99801 ). Returns a |
|
235 |
* has of the name value pairs, hashed on name. |
|
236 |
*/ |
|
237 |
public static Hashtable parseQuery(String query) throws MalformedURLException |
|
238 |
{ |
|
239 |
String[][] params = new String[200][2]; |
|
240 |
Hashtable parameters = new Hashtable(); |
|
241 |
|
|
242 |
String temp = ""; |
|
243 |
boolean ampflag = true; |
|
244 |
boolean poundflag = false; |
|
245 |
int arrcount = 0; |
|
246 |
|
|
247 |
for (int i=0; i < query.length(); i++) { |
|
248 |
|
|
249 |
// go throught the remainder of the query one character at a time. |
|
250 |
if (query.charAt(i) == '=') { |
|
251 |
// if the current char is a # then the preceding should be a name |
|
252 |
if (!poundflag && ampflag) { |
|
253 |
params[arrcount][0] = temp.trim(); |
|
254 |
temp = ""; |
|
255 |
} else { |
|
256 |
//if there are two #s or &s in a row throw an exception. |
|
257 |
throw new MalformedURLException("metacatURL: Two parameter names " + "not allowed in sequence"); |
|
258 |
} |
|
259 |
poundflag = true; |
|
260 |
ampflag = false; |
|
261 |
} else if (query.charAt(i) == '&' || i == query.length()-1) { |
|
262 |
//the text preceding the & should be the param value. |
|
263 |
if (i == query.length() - 1) { |
|
264 |
//if at the end of the string grab the last value and append it. |
|
265 |
if (query.charAt(i) != '=') { |
|
266 |
//ignore an extra & on the end of the string |
|
267 |
temp += query.charAt(i); |
|
268 |
} |
|
269 |
} |
|
270 |
|
|
271 |
if (!ampflag && poundflag) { |
|
272 |
params[arrcount][1] = temp.trim(); |
|
273 |
parameters.put(params[arrcount][0], params[arrcount][1]); |
|
274 |
temp = ""; |
|
275 |
arrcount++; //increment the array to the next row. |
|
276 |
} else { |
|
277 |
//if there are two =s or &s in a row through an exception |
|
278 |
throw new MalformedURLException("metacatURL: Two parameter values " + |
|
279 |
"not allowed in sequence"); |
|
280 |
} |
|
281 |
poundflag = false; |
|
282 |
ampflag = true; |
|
283 |
} else { |
|
284 |
//get the next character in the string |
|
285 |
temp += query.charAt(i); |
|
286 |
} |
|
287 |
} |
|
288 |
return parameters; |
|
289 |
} |
|
290 |
|
|
291 |
/** |
|
231 | 292 |
* Utility method to print debugging messages |
232 | 293 |
* |
233 | 294 |
* @param flag an integer indicating the message number |
... | ... | |
249 | 310 |
} |
250 | 311 |
} |
251 | 312 |
} |
252 |
|
|
253 |
/** |
|
254 |
* '$Log$ |
|
255 |
* 'Revision 1.15 2000/08/14 22:31:13 berkley |
|
256 |
* 'added new constructor to allow the creation of a metacatutil object that uses a properties file other than edu.ucsb.nceas.metacat.metacat. |
|
257 |
* ' |
|
258 |
* 'Revision 1.14 2000/08/14 20:53:34 jones |
|
259 |
* 'Added "release" keyword to all metacat source files so that the release |
|
260 |
* 'number will be evident in software distributions. |
|
261 |
* ' |
|
262 |
* 'Revision 1.13 2000/08/09 00:39:47 jones |
|
263 |
* '-Reorganized xmltodb module to support new install process for the new |
|
264 |
* 'linux server (dev.nceas.ucsb.edu). Added "build.sh" shell script that |
|
265 |
* 'calls ant withthe proper umask set for installation. Use: |
|
266 |
* ' |
|
267 |
* ' ./build.sh install |
|
268 |
* ' |
|
269 |
* 'to post a new copy of the servlet and its supporting files to the install |
|
270 |
* 'directory defined in build.xml. |
|
271 |
* ' |
|
272 |
* '-Updated the servlet to use a new servlet prefix that we'll use with the |
|
273 |
* 'Tomcat servlet engine. |
|
274 |
* ' |
|
275 |
* '-Update bin dir shell scripts to reflect new locations of relevant jar files. |
|
276 |
* ' |
|
277 |
* 'Revision 1.12 2000/08/04 23:34:10 bojilova |
|
278 |
* 'more precise handling of the Connection Pool |
|
279 |
* ' |
|
280 |
* 'Revision 1.11 2000/08/01 18:26:50 bojilova |
|
281 |
* 'added Pool of Connections |
|
282 |
* 'DBQuery, DBReader, DBTransform, DBUtil are created on every request and use the connections from the Pool |
|
283 |
* 'same with DBWriter and DBValidate |
|
284 |
* ' |
|
285 |
* 'Revision 1.10 2000/06/26 10:35:05 jones |
|
286 |
* 'Merged in substantial changes to DBWriter and associated classes and to |
|
287 |
* 'the MetaCatServlet in order to accomodate the new UPDATE and DELETE |
|
288 |
* 'functions. The command line tools and the parameters for the |
|
289 |
* 'servlet have changed substantially. |
|
290 |
* ' |
|
291 |
* 'Revision 1.9.2.4 2000/06/26 00:51:06 jones |
|
292 |
* 'If docid passed to DBWriter.write() is not unique, classes now generate |
|
293 |
* 'an AccessionNumberException containing the new docid generated as a |
|
294 |
* 'replacement. The docid is then extracted from the exception and |
|
295 |
* 'returned to the calling application for user feedback or client processing. |
|
296 |
* ' |
|
297 |
* 'Revision 1.9.2.3 2000/06/25 23:38:17 jones |
|
298 |
* 'Added RCSfile keyword |
|
299 |
* ' |
|
300 |
* 'Revision 1.9.2.2 2000/06/25 23:34:18 jones |
|
301 |
* 'Changed documentation formatting, added log entries at bottom of source files |
|
302 |
* '' |
|
303 |
*/ |
Also available in: Unified diff
Modified stylesheets and server code to use a single "read" action instead
of the earlier "getdocument" and "getrelateddocument" actions. In the
process, developed and started to utilize a new suite of URL "protocol
handlers" that are in the package "edu.ucsb.nceas.protocols" and handle
the parsing of various forms of URLS (mainly metacat:// protocol URLS). New
protocols can be added by following the model for the metacat protocol handler.
Using this mechanism, the standard URL handling methods like "getProtocol()"
can be used, and I added the "parseQuery()" method to MetaCatUtil for
parsing query parameters into name/value pairs and returning a hashtable.
I've eliminated the use of the MetacatURL class from the main Metacat servlet
classes, but not yet from the replication server classes (because I don't
understand the implications of doing so yet).