Created
August 21, 2009 14:31
-
-
Save vrutberg/172053 to your computer and use it in GitHub Desktop.
Query Parser class for Lotus Notes/Domino written in Java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private class QueryParser { | |
public Hashtable parseQueryString(String qsd) { | |
// we will return this | |
Hashtable data = new Hashtable(); | |
// check if it contains pairs of k/v | |
if(qsd.indexOf("&") > -1) { | |
String[] pairs = qsd.split("&"); | |
for(int i = 0; i < pairs.length; i++) { | |
// check if it contains k/v | |
if(pairs[i].indexOf("=") > -1) { | |
String[] kv = pairs[i].split("="); | |
if(kv.length == 2) { | |
data.put(kv[0].toLowerCase(), kv[1]); | |
} else { | |
data.put(kv[0].toLowerCase(), ""); | |
} | |
} | |
// okay, no k/v, just a value (not empty) | |
else if(!pairs[i].equals("")) { | |
data.put(pairs[i].toLowerCase(), ""); | |
} | |
} | |
} | |
// okay, no pairs, what about a single k/v? | |
else if(qsd.indexOf("=") > -1) { | |
String[] kv = qsd.split("="); | |
if(kv.length == 2) { | |
data.put(kv[0].toLowerCase(), kv[1]); | |
} | |
} | |
// no pairs and no k/v, just a value (not empty) | |
else if(!qsd.equals("")) { | |
data.put(qsd.toLowerCase(), ""); | |
} | |
return data; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment