package com.google.gwt.query.client;\r
\r
import com.google.gwt.core.client.JavaScriptObject;\r
+import com.google.gwt.core.client.JsArrayMixed;\r
import com.google.gwt.query.client.js.JsCache;\r
\r
/**\r
public static Properties create(String properties) {\r
if (properties != null && !properties.isEmpty()) {\r
String p = camelizePropertiesKeys(wrapPropertiesString(properties));\r
+ System.out.println(p);\r
try {\r
return (Properties) createImpl(p);\r
} catch (Exception e) {\r
.replaceFirst("^[{\\(]+(|.*[^}\\)])[}\\)]+$", "$1") // Remove ({})\r
.replaceAll("\\('([^\\)]+)'\\)" , "($1)") // Remove quotes\r
.replaceAll(",+([\\w-]+:+)" , ";$1") // put semicolon\r
- .replaceAll(":\\s*[\"']?([^';]*)[\"']?\\s*(;+|$)", ":'$1',") // put quotes\r
+ .replaceAll(":\\s*[\"']?([^'\\]};]*)[\"']?\\s*(;+|$)", ":'$1',") // put quotes\r
.replaceAll(":'(-?[\\d\\.]+|null|false|true)',", ":$1,") // numbers do not need quote\r
.replaceFirst("[;,]$", "") // remove endings \r
+ "})";\r
}\r
\r
public final <T> T get(Object name) {\r
- return c().<T>get(String.valueOf(name));\r
+ return c().get(String.valueOf(name));\r
}\r
\r
public final boolean getBoolean(Object name) {\r
public final String getStr(Object name) {\r
return c().getString(String.valueOf(name));\r
}\r
+ \r
+ public final Object getObject(Object name) {\r
+ return c().get(String.valueOf(name));\r
+ }\r
+ \r
+ public final <T extends JavaScriptObject> T getJavaScriptObject(Object name) {\r
+ return c().getJavaScriptObject(String.valueOf(name));\r
+ }\r
\r
+ public final JsArrayMixed getArray(Object name) {\r
+ return c().getArray(String.valueOf(name));\r
+ }\r
+ \r
public final String[] keys() {\r
return c().keys();\r
}\r
}\r
\r
public final String tostring() {\r
+ return "(" + toJsonString() + ")";\r
+ }\r
+ \r
+ public final String toJsonString() {\r
String ret = "";\r
+ \r
for (String k : keys()){\r
- ret += k + ": '" + getStr(k) + "', ";\r
+ JsArrayMixed o = getArray(k);\r
+ if (o != null) {\r
+ ret += k + ":[";\r
+ for (int i = 0, l = o.length(); i < l ; i++) {\r
+ ret += "'" + o.getString(i) + "',";\r
+ }\r
+ ret += "],";\r
+ } else {\r
+ Properties p = getJavaScriptObject(k);\r
+ if (p != null) {\r
+ ret += k + ":" + p.toJsonString();\r
+ } else {\r
+ ret += k + ":'" + getStr(k) + "',";\r
+ }\r
+ }\r
}\r
- return "({" + ret.replaceAll("[, ]+$","") + "})";\r
+ return "{" + ret.replaceAll(",\\s*([\\]}]|$)","").replaceAll("([:,\\[])'(-?[\\d\\.]+|null|false|true)'", "$1$2") + "}";\r
+ }\r
+ \r
+ public final String toQueryString() {\r
+ String ret = "";\r
+ for (String k : keys()) {\r
+ ret += ret.isEmpty() ? "" : "&";\r
+ JsArrayMixed o = getArray(k);\r
+ if (o != null) {\r
+ for (int i = 0, l = o.length(); i < l ; i++) {\r
+ ret += (i > 0 ? "&" : "") + k + "[]=" + o.getString(i) ;\r
+ }\r
+ } else {\r
+ Properties p = getJavaScriptObject(k);\r
+ if (p != null) {\r
+ ret += p.toQueryString();\r
+ } else {\r
+ ret += k + "=" + getStr(k);\r
+ }\r
+ }\r
+ }\r
+ return ret;\r
}\r
}\r
package com.google.gwt.query.client.js;
import com.google.gwt.core.client.JavaScriptObject;
+import com.google.gwt.core.client.JsArrayMixed;
import com.google.gwt.core.client.JsArrayString;
/**
}
}
- public final native void delete(int name) /*-{
+ public final native <T> void delete(T name) /*-{
delete this[name];
}-*/;
- public final native void delete(String name) /*-{
- delete this[name];
- }-*/;
-
- public final native boolean exists(String name) /*-{
+ public final native <T> boolean exists(T name) /*-{
return !!this[name];
}-*/;
- public final native boolean exists(int id) /*-{
- return !!this[id];
- }-*/;
-
- public final native <T> T get(int id) /*-{
+ public final native <R, T> R get(T id) /*-{
return this[id] || null;
}-*/;
- public final native <T> T get(String id) /*-{
- return this[id] || null;
- }-*/;
-
- public final JsCache getCache(int id) {
+ public final <T> JsCache getCache(int id) {
return (JsCache)get(id);
}
- public final native boolean getBoolean(int id) /*-{
- return !!this[id];
- }-*/;
-
- public final native boolean getBoolean(String id) /*-{
+ public final native <T> boolean getBoolean(T id) /*-{
return !!this[id];
}-*/;
- public final native float getFloat(int id) /*-{
- return this[id] || 0;
- }-*/;
-
- public final native float getFloat(String id) /*-{
+ public final native <T> float getFloat(T id) /*-{
return this[id] || 0;
}-*/;
- public final native double getDouble(int id) /*-{
+ public final native <T> double getDouble(T id) /*-{
return this[id] || 0;
}-*/;
- public final native double getDouble(String id) /*-{
- return this[id] || 0;
- }-*/;
-
- public final native int getInt(int id) /*-{
- return this[id] || 0;
- }-*/;
-
- public final native int getInt(String id) /*-{
+ public final native <T> int getInt(T id) /*-{
return this[id] || 0;
}-*/;
- public final native String getString(int id) /*-{
+ public final native <T> String getString(T id) /*-{
return this[id] == null ? null : String(this[id]);
}-*/;
-
- public final native String getString(String id) /*-{
- return this[id] == null ? null : String(this[id]);
+
+ public final native <T> JsArrayMixed getArray(T id) /*-{
+ var r = this[id];
+ if (r != null && Object.prototype.toString.call(r) == '[object Array]') {
+ return r;
+ }
+ return null;
}-*/;
+
+ public final <T extends JavaScriptObject> T getJavaScriptObject(Object name) {
+ Object o = get(name);
+ return (o instanceof JavaScriptObject) ? ((JavaScriptObject)o).<T>cast() : null;
+ }
public final native boolean isEmpty() /*-{
for (k in this) return false;
return true;
}-*/;
- public final native void put(int id, Object obj) /*-{
+ public final native <T, O> void put(T id, O obj) /*-{
this[id] = obj;
}-*/;
- public final native void put(String id, Object obj) /*-{
- this[id] = obj;
- }-*/;
-
public final native int length() /*-{
if (typeof(this.length) == 'number')
return this.length;