/** * Transforms a encoded array of strings back. * * @param in * @return decoded parts */ public static String[] explodeArray(String in) { if ( in == null || in.length()==0) return new String[0]; String[] out = in.split("&"); for (int i = 0; i < out.length; i++) out[i]=decode(out[i]); return out; }
if (getScheme() != null) { out.append(getScheme()).append(':'); if (getUsername() != null) { out.append("//").append(getUsername()); if (getPassword() != null) out.append(':').append(getPassword()); out.append("@"); if (getLocation() != null) out.append(getLocation()); } else if (getLocation() != null) out.append("//").append(getLocation()); if (MString.isSet(getPath()) && getLocation() != null && !getPath().startsWith("/")) out.append('/'); if (MString.isSet(getPath())) out.append(getPath()); if (getParams() != null) for (String p : getParams()) out.append(';').append(encode(p)); if (getQuery() != null) { out.append('?'); boolean first = true; for (Entry<String, String> entry : getQuery().entrySet()) { if (first) first = false;
/** * This will handle the strings like options. Means a string without separator will handled * as key and set to true. e.g. val1&val2&a=b will be val1=true, val2=true, a=b * * @param properties Rfc1738 (Url Encode) encoded string * @return The MProperties */ public static MProperties explodeToOptions(String properties) { return explodeToOptions(MUri.explodeArray(properties), '='); }
prop.put("name", caze.getCanonicalName()); prop.put("uri", M.trunc(caze.getUri(), 700)); MUri u = MUri.toUri(caze.getUri()); prop.put("process", MString.beforeIndex(u.getLocation(), ':')); prop.put("version", MString.afterIndex(u.getLocation(),':')); prop.put("pool", u.getPath());
/** * Transform the elements of an array to a string using the rfc1738 sprec. * @param in * @return encoded string */ public static String implodeArray(String ... in) { if (in==null) return ""; StringBuilder sb = new StringBuilder(); boolean first = true; for ( String i : in ) { if (!first) sb.append('&'); sb.append(encode(i)); first = false; } return sb.toString(); }
out.append("&type=").append(type); out.append("&description=").append(MUri.encode(pa.description())); if (pa.hints().length > 0) out.append("&hints=").append(MUri.encode(MUri.implodeArray(pa.hints())));
public String getMsgCaption() { if (MString.isSet(msg) && msg.startsWith("m=")) { Map<String, String> msgParts = MUri.explode(msg); return msgParts.get("c"); } return null; }
/** * encode a string in rfc1738 spec * @param _in decoded string * @return encoded string */ public static String encode(String _in) { if (_in == null) return ""; try { return URLEncoder.encode(_in,MString.CHARSET_DEFAULT); // as default charset } catch (UnsupportedEncodingException e) { //TODO log } return encodeNoUTF8(_in); }
prop.put("customer", M.trunc(caze.getCustomerId(), 700)); prop.put("uri", M.trunc(caze.getUri(), 700)); MUri u = MUri.toUri(caze.getUri()); prop.put("process", MString.beforeIndex(u.getLocation(), ':')); prop.put("version", MString.afterIndex(u.getLocation(),':')); prop.put("pool", u.getPath());
public static void setParameterValue(String url, String name, String value) { name = encode(name) + "="; value = encode(value); int pos = url.indexOf("&" + name); if (pos < 0) { pos = url.indexOf("?" + name); } if (pos < 0) { if (url.contains("?")) url = url + "&"; else url = url + "?"; url = url + name + value; } else { int pos2 = url.indexOf("&",pos+1); if (pos2 < 0) { url = url.substring(0, pos+1+name.length()) + value; } else { url = url.substring(0, pos+1+name.length()) + value + url.substring(pos2); } } }
public String getMsgMessage() { if (MString.isSet(msg) && msg.startsWith("m=")) { Map<String, String> msgParts = MUri.explode(msg); return msgParts.get("m"); } return msg; }
public static String encode(char c) { StringBuilder sb = new StringBuilder(); encodeNoUTF8(sb, c); return sb.toString(); }
prop.put("name", caze.getCanonicalName()); prop.put("uri", M.trunc(caze.getUri(), 700)); MUri u = MUri.toUri(caze.getUri()); prop.put("process", MString.beforeIndex(u.getLocation(), ':')); prop.put("version", MString.afterIndex(u.getLocation(),':')); prop.put("pool", u.getPath());
/** * Transforms a list encoded map of attributes back. * * @param _in * @return decoded parts */ public static Map<String,String> explode(String _in) { if (_in == null) return new TreeMap<String,String>(); TreeMap<String,String> out = new TreeMap<String,String>(); String[] obj = _in.split("&"); for (int i = 0; i < obj.length; i++) { String[] kv = obj[i].split("="); if (kv.length == 2) { if (kv[1] == null) kv[1] = ""; out.put(decode(kv[0]), decode(kv[1])); } else if (kv.length == 1) out.put(decode(kv[0]), ""); } return out; }
/** * Encode a list of attributes in a single string * @param _in * @return encoded string */ public static String implode(Map<String,String> _in) { if (_in == null) return ""; StringBuilder sb = new StringBuilder(); boolean first = true; for (Iterator<String> e = _in.keySet().iterator(); e.hasNext();) { String key = e.next(); String value = _in.get(key); if (value != null) { if (!first) sb.append('&'); sb.append(encode(key)); sb.append('='); sb.append(encode(value)); first = false; } } return sb.toString(); }
/** * This will handle the strings like properties. Means a string without separator will be * stored as value with an increasing key as integer, e.g. val1&val2&a=b will be 0=val1, 1=val2, a=b * @param properties Rfc1738 (Url Encoded) encoded string * @return The MProperties */ public static MProperties explodeToMProperties(String properties) { return explodeToMProperties(MUri.explodeArray(properties), '=', ':', 0, Integer.MAX_VALUE); }
return new HashConfig(MUri.explode(configString)); else return new PropertiesConfig(configString);
public static String encodeNoUTF8(String _in) { StringBuilder sb = new StringBuilder(); for (int i = 0; i < _in.length(); i++) { char c = _in.charAt(i); // if (c == '%' || c == '&' || c == '=' || c == '+' || c == '\n' // || c == '\r' || c == '?' || c == ' ' ) if (! (c >= 'A' && c <= 'Z' || c >= 'a' && c <= 'z' || c >= '0' && c <= '9' || c == ',' || c == '.' ) ) { encodeNoUTF8(sb, c); } else sb.append(c); } return sb.toString(); }
prop.put("customer", M.trunc(caze.getCustomerId(), 700)); prop.put("uri", M.trunc(caze.getUri(), 700)); MUri u = MUri.toUri(caze.getUri()); prop.put("process", MString.beforeIndex(u.getLocation(), ':')); prop.put("version", MString.afterIndex(u.getLocation(),':')); prop.put("pool", u.getPath());
public static String[] explodeArray(String in, char split) { if ( in == null || in.length()==0) return new String[0]; String[] out = MString.split(in, String.valueOf(split)); for (int i = 0; i < out.length; i++) out[i]=decode(out[i]); return out; }