use of lucee.commons.lang.StringList in project Lucee by lucee.
the class HTTPUtil method decodeQuery.
private static String decodeQuery(String query, char startDelimiter) {
if (!StringUtil.isEmpty(query)) {
StringBuilder res = new StringBuilder();
StringList list = ListUtil.toList(query, '&');
String str;
int index;
char del = startDelimiter;
while (list.hasNext()) {
res.append(del);
del = '&';
str = list.next();
index = str.indexOf('=');
if (index == -1)
res.append(escapeQSValue(str));
else {
res.append(escapeQSValue(str.substring(0, index)));
res.append('=');
res.append(escapeQSValue(str.substring(index + 1)));
}
}
query = res.toString();
} else
query = "";
return query;
}
use of lucee.commons.lang.StringList in project Lucee by lucee.
the class HTTPUtil method encode.
// MUST create a copy from toURL and rename toURI and rewrite for URI, pherhaps it is possible to merge them somehow
public static String encode(String realpath) {
int qIndex = realpath.indexOf('?');
if (qIndex == -1)
return realpath;
String file = realpath.substring(0, qIndex);
String query = realpath.substring(qIndex + 1);
int sIndex = query.indexOf('#');
String anker = null;
if (sIndex != -1) {
// print.o(sIndex);
anker = query.substring(sIndex + 1);
query = query.substring(0, sIndex);
}
StringBuilder res = new StringBuilder(file);
// query
if (!StringUtil.isEmpty(query)) {
StringList list = ListUtil.toList(query, '&');
String str;
int index;
char del = '?';
while (list.hasNext()) {
res.append(del);
del = '&';
str = list.next();
index = str.indexOf('=');
if (index == -1)
res.append(escapeQSValue(str));
else {
res.append(escapeQSValue(str.substring(0, index)));
res.append('=');
res.append(escapeQSValue(str.substring(index + 1)));
}
}
}
// anker
if (anker != null) {
res.append('#');
res.append(escapeQSValue(anker));
}
return res.toString();
}
Aggregations