Search in sources :

Example 21 with StringList

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;
}
Also used : StringList(lucee.commons.lang.StringList)

Example 22 with StringList

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();
}
Also used : StringList(lucee.commons.lang.StringList)

Aggregations

StringList (lucee.commons.lang.StringList)22 ParserString (lucee.commons.lang.ParserString)10 PageException (lucee.runtime.exp.PageException)4 Collection (lucee.runtime.type.Collection)2 URI (java.net.URI)1 URL (java.net.URL)1 HashMap (java.util.HashMap)1 CastableStruct (lucee.runtime.type.CastableStruct)1 Struct (lucee.runtime.type.Struct)1 VariableReference (lucee.runtime.type.ref.VariableReference)1 CollectionKey (lucee.transformer.bytecode.expression.type.CollectionKey)1 CollectionKeyArray (lucee.transformer.bytecode.expression.type.CollectionKeyArray)1 Argument (lucee.transformer.bytecode.expression.var.Argument)1 Expression (lucee.transformer.expression.Expression)1 LitString (lucee.transformer.expression.literal.LitString)1 Version (org.osgi.framework.Version)1