Search in sources :

Example 1 with StringList

use of lucee.commons.lang.StringList in project Lucee by lucee.

the class OSGiUtil method toPackageDefinition.

private static PackageDefinition toPackageDefinition(String str, String filterPackageName, List<VersionDefinition> versionDefinitions) {
    // first part is the package
    StringList list = ListUtil.toList(str, ';');
    PackageDefinition pd = null;
    String token;
    Version v;
    while (list.hasNext()) {
        token = list.next().trim();
        if (pd == null) {
            if (!token.equals(filterPackageName))
                return null;
            pd = new PackageDefinition(token);
        } else // only intressted in version
        {
            StringList entry = ListUtil.toList(token, '=');
            if (entry.size() == 2 && entry.next().trim().equalsIgnoreCase("version")) {
                String version = StringUtil.unwrap(entry.next().trim());
                if (!version.equals("0.0.0")) {
                    v = OSGiUtil.toVersion(version, null);
                    if (v != null) {
                        if (versionDefinitions != null) {
                            Iterator<VersionDefinition> it = versionDefinitions.iterator();
                            while (it.hasNext()) {
                                if (!it.next().matches(v)) {
                                    return null;
                                }
                            }
                        }
                        pd.setVersion(v);
                    }
                }
            }
        }
    }
    return pd;
}
Also used : StringList(lucee.commons.lang.StringList) Version(org.osgi.framework.Version)

Example 2 with StringList

use of lucee.commons.lang.StringList in project Lucee by lucee.

the class HTTPUtil method toURI.

public static URI toURI(String strUrl, int port) throws URISyntaxException {
    // print.o((strUrl));
    URI uri = new URI(strUrl);
    String host = uri.getHost();
    String fragment = uri.getRawFragment();
    String path = uri.getRawPath();
    String query = uri.getRawQuery();
    String scheme = uri.getScheme();
    String userInfo = uri.getRawUserInfo();
    if (port <= 0)
        port = uri.getPort();
    // decode path
    if (!StringUtil.isEmpty(path)) {
        int sqIndex = path.indexOf(';');
        String q = null;
        if (sqIndex != -1) {
            q = path.substring(sqIndex + 1);
            path = path.substring(0, sqIndex);
        }
        StringBuilder res = new StringBuilder();
        StringList list = ListUtil.toListTrim(path, '/');
        String str;
        while (list.hasNext()) {
            str = list.next();
            if (StringUtil.isEmpty(str))
                continue;
            res.append("/");
            res.append(escapeQSValue(str));
        }
        if (StringUtil.endsWith(path, '/'))
            res.append('/');
        path = res.toString();
        if (sqIndex != -1) {
            path += decodeQuery(q, ';');
        }
    }
    // decode query
    query = decodeQuery(query, '?');
    // decode ref/anchor
    if (!StringUtil.isEmpty(fragment)) {
        fragment = escapeQSValue(fragment);
    }
    // user/pasword
    if (!StringUtil.isEmpty(userInfo)) {
        int index = userInfo.indexOf(':');
        if (index != -1) {
            userInfo = escapeQSValue(userInfo.substring(0, index)) + ":" + escapeQSValue(userInfo.substring(index + 1));
        } else
            userInfo = escapeQSValue(userInfo);
    }
    /*print.o("- fragment:"+fragment);
    	print.o("- host:"+host);
    	print.o("- path:"+path);
    	print.o("- query:"+query);
    	print.o("- scheme:"+scheme);
    	print.o("- userInfo:"+userInfo);
    	print.o("- port:"+port);
    	print.o("- absolute:"+uri.isAbsolute());
    	print.o("- opaque:"+uri.isOpaque());*/
    StringBuilder rtn = new StringBuilder();
    if (scheme != null) {
        rtn.append(scheme);
        rtn.append("://");
    }
    if (userInfo != null) {
        rtn.append(userInfo);
        rtn.append("@");
    }
    if (host != null) {
        rtn.append(host);
    }
    if (port > 0) {
        rtn.append(":");
        rtn.append(port);
    }
    if (path != null) {
        rtn.append(path);
    }
    if (query != null) {
        // rtn.append("?");
        rtn.append(query);
    }
    if (fragment != null) {
        rtn.append("#");
        rtn.append(fragment);
    }
    return new URI(rtn.toString());
}
Also used : StringList(lucee.commons.lang.StringList) URI(java.net.URI)

Example 3 with StringList

use of lucee.commons.lang.StringList in project Lucee by lucee.

the class HTTPUtil method encodeURL.

public static URL encodeURL(URL url, int port) throws MalformedURLException {
    // file
    String path = url.getPath();
    // String file=url.getFile();
    String query = url.getQuery();
    String ref = url.getRef();
    String user = url.getUserInfo();
    if (port <= 0)
        port = url.getPort();
    // decode path
    if (!StringUtil.isEmpty(path)) {
        int sqIndex = path.indexOf(';');
        String q = null;
        if (sqIndex != -1) {
            q = path.substring(sqIndex + 1);
            path = path.substring(0, sqIndex);
        }
        StringBuilder res = new StringBuilder();
        StringList list = ListUtil.toListTrim(path, '/');
        String str;
        while (list.hasNext()) {
            str = list.next();
            if (StringUtil.isEmpty(str))
                continue;
            res.append("/");
            res.append(escapeQSValue(str));
        }
        if (StringUtil.endsWith(path, '/'))
            res.append('/');
        path = res.toString();
        if (sqIndex != -1) {
            path += decodeQuery(q, ';');
        }
    }
    // decode query
    query = decodeQuery(query, '?');
    String file = path + query;
    // decode ref/anchor
    if (ref != null) {
        file += "#" + escapeQSValue(ref);
    }
    // user/pasword
    if (!StringUtil.isEmpty(user)) {
        int index = user.indexOf(':');
        if (index != -1) {
            user = escapeQSValue(user.substring(0, index)) + ":" + escapeQSValue(user.substring(index + 1));
        } else
            user = escapeQSValue(user);
        String strUrl = getProtocol(url) + "://" + user + "@" + url.getHost();
        if (port > 0)
            strUrl += ":" + port;
        strUrl += file;
        return new URL(strUrl);
    }
    // port
    if (port <= 0)
        return new URL(url.getProtocol(), url.getHost(), file);
    return new URL(url.getProtocol(), url.getHost(), port, file);
}
Also used : StringList(lucee.commons.lang.StringList) URL(java.net.URL)

Example 4 with StringList

use of lucee.commons.lang.StringList in project Lucee by lucee.

the class HTTPUtil method parseParameterList.

/*public static ContentType getContentType(HttpMethod http) {
		Header[] headers = http.getResponseHeaders();
		for(int i=0;i<headers.length;i++){
			if("Content-Type".equalsIgnoreCase(headers[i].getName())){
				String[] mimeCharset = splitMimeTypeAndCharset(headers[i].getValue());
				String[] typeSub = splitTypeAndSubType(mimeCharset[0]);
				return new ContentTypeImpl(typeSub[0],typeSub[1],mimeCharset[1]);
			}
		}
		return null;
	}*/
public static Map<String, String> parseParameterList(String _str, boolean decode, String charset) {
    // return lucee.commons.net.HTTPUtil.toURI(strUrl,port);
    Map<String, String> data = new HashMap<String, String>();
    StringList list = ListUtil.toList(_str, '&');
    String str;
    int index;
    while (list.hasNext()) {
        str = list.next();
        index = str.indexOf('=');
        if (index == -1) {
            data.put(decode(str, decode), "");
        } else {
            data.put(decode(str.substring(0, index), decode), decode(str.substring(index + 1), decode));
        }
    }
    return data;
}
Also used : HashMap(java.util.HashMap) StringList(lucee.commons.lang.StringList)

Example 5 with StringList

use of lucee.commons.lang.StringList in project Lucee by lucee.

the class ScopeSupport method fillDecoded.

/**
 * fill th data from given strut and decode it
 *
 * @param raw
 * @param encoding
 * @throws UnsupportedEncodingException
 */
protected void fillDecoded(URLItem[] raw, String encoding, boolean scriptProteced, boolean sameAsArray) throws UnsupportedEncodingException {
    clear();
    String name, value;
    // Object curr;
    for (int i = 0; i < raw.length; i++) {
        name = raw[i].getName();
        value = raw[i].getValue();
        if (raw[i].isUrlEncoded()) {
            name = URLDecoder.decode(name, encoding, true);
            value = URLDecoder.decode(value, encoding, true);
        }
        // MUST valueStruct
        if (name.indexOf('.') != -1) {
            StringList list = ListUtil.listToStringListRemoveEmpty(name, '.');
            if (list.size() > 0) {
                Struct parent = this;
                while (list.hasNextNext()) {
                    parent = _fill(parent, list.next(), new CastableStruct(Struct.TYPE_LINKED), false, scriptProteced, sameAsArray);
                }
                _fill(parent, list.next(), value, true, scriptProteced, sameAsArray);
            }
        }
        // else
        _fill(this, name, value, true, scriptProteced, sameAsArray);
    }
}
Also used : StringList(lucee.commons.lang.StringList) CastableStruct(lucee.runtime.type.CastableStruct) Struct(lucee.runtime.type.Struct) CastableStruct(lucee.runtime.type.CastableStruct)

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