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;
}
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());
}
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);
}
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;
}
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);
}
}
Aggregations