My favorites
▼
|
Sign in
totoe
JSON and XML parser for GWT with json/xpath and namespace support
Project Home
Downloads
Wiki
Issues
Source
READ-ONLY: This project has been
archived
. For more information see
this post
.
Search
Search within:
All issues
Open issues
New issues
Issues to verify
for
Advanced search
Search tips
Subscriptions
Issue
8
attachment: totoe_path.diff
(5.0 KB)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
Index: core/src/main/resources/name/pehl/totoe/json/JSON.gwt.xml
===================================================================
--- core/src/main/resources/name/pehl/totoe/json/JSON.gwt.xml (revision 373)
+++ core/src/main/resources/name/pehl/totoe/json/JSON.gwt.xml (working copy)
@@ -9,5 +9,5 @@
<inherits name="com.google.gwt.user.User" />
<inherits name="name.pehl.totoe.commons.Commons" />
- <script src="jsonpath.js" />
+
</module>
Index: core/src/main/resources/name/pehl/totoe/xml/XML.gwt.xml
===================================================================
--- core/src/main/resources/name/pehl/totoe/xml/XML.gwt.xml (revision 373)
+++ core/src/main/resources/name/pehl/totoe/xml/XML.gwt.xml (working copy)
@@ -9,6 +9,4 @@
<inherits name="com.google.gwt.xml.XML" />
<inherits name="name.pehl.totoe.commons.Commons" />
- <script src="gr/abiss/js/sarissa/sarissa.js" />
- <script src="gr/abiss/js/sarissa/sarissa_ieemu_xpath.js" />
</module>
Index: core/src/main/java/name/pehl/totoe/json/client/JsonPath.java
===================================================================
--- core/src/main/java/name/pehl/totoe/json/client/JsonPath.java (revision 373)
+++ core/src/main/java/name/pehl/totoe/json/client/JsonPath.java (working copy)
@@ -2,10 +2,14 @@
import com.google.gwt.core.client.JavaScriptException;
import com.google.gwt.core.client.JavaScriptObject;
+import com.google.gwt.core.client.ScriptInjector;
+import com.google.gwt.core.shared.GWT;
import com.google.gwt.json.client.JSONException;
import com.google.gwt.json.client.JSONNull;
import com.google.gwt.json.client.JSONObject;
import com.google.gwt.json.client.JSONValue;
+import com.google.gwt.resources.client.ClientBundle;
+import com.google.gwt.resources.client.TextResource;
/**
* Java wrapper for <a
@@ -20,13 +24,25 @@
public final class JsonPath
{
+
+ interface ResourceBundle extends ClientBundle {
+
+ ResourceBundle INSTANCE = GWT.create(ResourceBundle.class);
+
+ @Source("public/jsonpath.js")
+ TextResource jsonPathJs();
+ }
+
/**
* Private constructor to ensure that the class acts as a true utility class
* i.e. it isn't instantiable and extensible.
*/
private JsonPath()
{
+ injectScript();
}
+
+
/**
@@ -61,6 +77,19 @@
throw new JSONException(e);
}
}
+
+ private static final native boolean isScriptInjected() /*-{
+ if (!(typeof $wnd.jsonPath === "undefined") && !(null===$wnd.jsonPath)) {
+ return true;
+ }
+ return false;
+ }-*/;
+
+ private static void injectScript() {
+ if (!isScriptInjected()) {
+ ScriptInjector.fromString(ResourceBundle.INSTANCE.jsonPathJs().getText()).setWindow(ScriptInjector.TOP_WINDOW).inject();
+ }
+ }
private static native JSONValue selectImpl(JavaScriptObject json, String path)
Index: core/src/main/java/name/pehl/totoe/xml/client/internal/XmlParserImpl.java
===================================================================
--- core/src/main/java/name/pehl/totoe/xml/client/internal/XmlParserImpl.java (revision 373)
+++ core/src/main/java/name/pehl/totoe/xml/client/internal/XmlParserImpl.java (working copy)
@@ -3,8 +3,12 @@
import name.pehl.totoe.xml.client.Document;
import name.pehl.totoe.xml.client.XmlParseException;
+import com.google.gwt.core.client.GWT;
import com.google.gwt.core.client.JavaScriptException;
import com.google.gwt.core.client.JavaScriptObject;
+import com.google.gwt.core.client.ScriptInjector;
+import com.google.gwt.resources.client.ClientBundle;
+import com.google.gwt.resources.client.TextResource;
/**
* @author $Author$
@@ -13,6 +17,17 @@
*/
public class XmlParserImpl
{
+
+ interface ResourceBundle extends ClientBundle {
+ ResourceBundle INSTANCE = GWT.create(ResourceBundle.class);
+
+ @Source("gr/abiss/js/sarissa/sarissa.js")
+ TextResource sarissaJs();
+
+ @Source("gr/abiss/js/sarissa_ieemu_xpath.js")
+ TextResource sarissaXPathJs();
+ }
+
// ------------------------------------------------------------------- JSNI
private static final JavaScriptObject nativeParser = XmlParserImpl.initialize();
@@ -20,11 +35,26 @@
private static JavaScriptObject initialize()
{
+ injectScript();
setupSarissaPrototypes();
return initializeDOMParser();
}
+ private static final native boolean isScriptInjected() /*-{
+ if (!(typeof $wnd.Sarissa === "undefined") && !(null===$wnd.Sarissa)) {
+ return true;
+ }
+ return false;
+ }-*/;
+ private static void injectScript() {
+ if (!isScriptInjected()) {
+ ScriptInjector.fromString(ResourceBundle.INSTANCE.sarissaJs().getText()).setWindow(ScriptInjector.TOP_WINDOW).inject();
+ ScriptInjector.fromString(ResourceBundle.INSTANCE.sarissaXPathJs().getText()).setWindow(ScriptInjector.TOP_WINDOW).inject();
+ }
+ }
+
+
/**
* Workaround for a bug where the Element javascript object is created in
* different scopes. Many thanks to Greg Hengeli! See <a
Powered by
Google Project Hosting