@capgo/capacitor-data-storage-sqlite 6.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CapacitorDataStorageSqlite.podspec +18 -0
- package/LICENSE +21 -0
- package/android/build.gradle +63 -0
- package/android/src/main/AndroidManifest.xml +3 -0
- package/android/src/main/java/com/jeep/plugin/capacitor/capacitordatastoragesqlite/CapacitorDataStorageSqlite.java +387 -0
- package/android/src/main/java/com/jeep/plugin/capacitor/capacitordatastoragesqlite/CapacitorDataStorageSqlitePlugin.java +447 -0
- package/android/src/main/java/com/jeep/plugin/capacitor/capacitordatastoragesqlite/RetHandler.java +117 -0
- package/android/src/main/java/com/jeep/plugin/capacitor/capacitordatastoragesqlite/cdssUtils/Data.java +8 -0
- package/android/src/main/java/com/jeep/plugin/capacitor/capacitordatastoragesqlite/cdssUtils/Global.java +7 -0
- package/android/src/main/java/com/jeep/plugin/capacitor/capacitordatastoragesqlite/cdssUtils/ImportExportJson/JsonStore.java +131 -0
- package/android/src/main/java/com/jeep/plugin/capacitor/capacitordatastoragesqlite/cdssUtils/ImportExportJson/JsonTable.java +110 -0
- package/android/src/main/java/com/jeep/plugin/capacitor/capacitordatastoragesqlite/cdssUtils/ImportExportJson/JsonValue.java +89 -0
- package/android/src/main/java/com/jeep/plugin/capacitor/capacitordatastoragesqlite/cdssUtils/StorageDatabaseHelper.java +691 -0
- package/android/src/main/java/com/jeep/plugin/capacitor/capacitordatastoragesqlite/cdssUtils/UtilsSQLCipher.java +162 -0
- package/android/src/main/res/.gitkeep +0 -0
- package/dist/docs.json +995 -0
- package/dist/esm/definitions.d.ts +296 -0
- package/dist/esm/definitions.js +2 -0
- package/dist/esm/definitions.js.map +1 -0
- package/dist/esm/index.d.ts +4 -0
- package/dist/esm/index.js +9 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/web-utils/Data.d.ts +5 -0
- package/dist/esm/web-utils/Data.js +3 -0
- package/dist/esm/web-utils/Data.js.map +1 -0
- package/dist/esm/web-utils/StorageDatabaseHelper.d.ts +23 -0
- package/dist/esm/web-utils/StorageDatabaseHelper.js +247 -0
- package/dist/esm/web-utils/StorageDatabaseHelper.js.map +1 -0
- package/dist/esm/web-utils/json-utils.d.ts +15 -0
- package/dist/esm/web-utils/json-utils.js +76 -0
- package/dist/esm/web-utils/json-utils.js.map +1 -0
- package/dist/esm/web.d.ts +27 -0
- package/dist/esm/web.js +295 -0
- package/dist/esm/web.js.map +1 -0
- package/dist/plugin.cjs.js +633 -0
- package/dist/plugin.cjs.js.map +1 -0
- package/dist/plugin.js +635 -0
- package/dist/plugin.js.map +1 -0
- package/electron/dist/plugin.js +1044 -0
- package/electron/dist/plugin.js.map +1 -0
- package/electron/rollup.config.mjs +17 -0
- package/electron/tsconfig.json +19 -0
- package/ios/Plugin/CapacitorDataStorageSqlite.swift +550 -0
- package/ios/Plugin/CapacitorDataStorageSqlitePlugin.h +10 -0
- package/ios/Plugin/CapacitorDataStorageSqlitePlugin.m +29 -0
- package/ios/Plugin/CapacitorDataStorageSqlitePlugin.swift +550 -0
- package/ios/Plugin/Data.swift +16 -0
- package/ios/Plugin/Global.swift +13 -0
- package/ios/Plugin/ImportExportJson/JsonStore.swift +47 -0
- package/ios/Plugin/Info.plist +24 -0
- package/ios/Plugin/ReturnHandler.swift +85 -0
- package/ios/Plugin/StorageDatabaseHelper.swift +603 -0
- package/ios/Plugin/Utils/Blob.swift +41 -0
- package/ios/Plugin/Utils/UtilsBinding.swift +73 -0
- package/ios/Plugin/Utils/UtilsEncryption.swift +79 -0
- package/ios/Plugin/Utils/UtilsFile.swift +244 -0
- package/ios/Plugin/Utils/UtilsSQLCipher.swift +605 -0
- package/package.json +96 -0
- package/readme.md +203 -0
|
@@ -0,0 +1,447 @@
|
|
|
1
|
+
package com.jeep.plugin.capacitor.capacitordatastoragesqlite;
|
|
2
|
+
|
|
3
|
+
import android.content.Context;
|
|
4
|
+
import com.getcapacitor.JSArray;
|
|
5
|
+
import com.getcapacitor.JSObject;
|
|
6
|
+
import com.getcapacitor.Plugin;
|
|
7
|
+
import com.getcapacitor.PluginCall;
|
|
8
|
+
import com.getcapacitor.PluginMethod;
|
|
9
|
+
import com.getcapacitor.annotation.CapacitorPlugin;
|
|
10
|
+
|
|
11
|
+
@CapacitorPlugin(name = "CapacitorDataStorageSqlite")
|
|
12
|
+
public class CapacitorDataStorageSqlitePlugin extends Plugin {
|
|
13
|
+
|
|
14
|
+
private CapacitorDataStorageSqlite implementation;
|
|
15
|
+
private RetHandler rHandler = new RetHandler();
|
|
16
|
+
private Context context;
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Load Method
|
|
20
|
+
* Load the context
|
|
21
|
+
*/
|
|
22
|
+
public void load() {
|
|
23
|
+
context = getContext();
|
|
24
|
+
implementation = new CapacitorDataStorageSqlite(context);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
@PluginMethod
|
|
28
|
+
public void echo(PluginCall call) {
|
|
29
|
+
String value = call.getString("value");
|
|
30
|
+
|
|
31
|
+
JSObject ret = new JSObject();
|
|
32
|
+
ret.put("value", implementation.echo(value));
|
|
33
|
+
call.resolve(ret);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
@PluginMethod
|
|
37
|
+
public void openStore(PluginCall call) {
|
|
38
|
+
String dbName = call.getString("database", "storage");
|
|
39
|
+
String tableName = call.getString("table", "storage_table");
|
|
40
|
+
Boolean encrypted = call.getBoolean("encrypted", false);
|
|
41
|
+
String secret = null;
|
|
42
|
+
String newsecret = null;
|
|
43
|
+
String inMode = null;
|
|
44
|
+
|
|
45
|
+
if (encrypted) {
|
|
46
|
+
inMode = call.getString("mode", "no-encryption");
|
|
47
|
+
if (
|
|
48
|
+
!inMode.equals("no-encryption") &&
|
|
49
|
+
!inMode.equals("encryption") &&
|
|
50
|
+
!inMode.equals("secret") &&
|
|
51
|
+
!inMode.equals("newsecret") &&
|
|
52
|
+
!inMode.equals("wrongsecret")
|
|
53
|
+
) {
|
|
54
|
+
String msg =
|
|
55
|
+
"OpenStore: Error inMode must be in ['encryption','secret'," +
|
|
56
|
+
"'newsecret']";
|
|
57
|
+
rHandler.retResult(call, null, msg);
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
} else {
|
|
61
|
+
inMode = "no-encryption";
|
|
62
|
+
}
|
|
63
|
+
try {
|
|
64
|
+
implementation.openStore(dbName, tableName, encrypted, inMode, 1);
|
|
65
|
+
rHandler.retResult(call, null, null);
|
|
66
|
+
return;
|
|
67
|
+
} catch (Exception e) {
|
|
68
|
+
String msg = "OpenStore: " + e.getMessage();
|
|
69
|
+
rHandler.retResult(call, null, msg);
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
@PluginMethod
|
|
75
|
+
public void closeStore(PluginCall call) {
|
|
76
|
+
if (!call.getData().has("database")) {
|
|
77
|
+
rHandler.retResult(call, false, "closeStore: Must provide a database");
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
String dbName = call.getString("database");
|
|
81
|
+
try {
|
|
82
|
+
implementation.closeStore(dbName);
|
|
83
|
+
rHandler.retResult(call, null, null);
|
|
84
|
+
return;
|
|
85
|
+
} catch (Exception e) {
|
|
86
|
+
String msg = "Close: " + e.getMessage();
|
|
87
|
+
rHandler.retResult(call, null, msg);
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
@PluginMethod
|
|
93
|
+
public void isStoreOpen(PluginCall call) {
|
|
94
|
+
boolean ret = false;
|
|
95
|
+
if (!call.getData().has("database")) {
|
|
96
|
+
rHandler.retResult(call, false, "IsStoreOpen: Must provide a database");
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
String dbName = call.getString("database");
|
|
100
|
+
try {
|
|
101
|
+
ret = implementation.isStoreOpen(dbName);
|
|
102
|
+
rHandler.retResult(call, ret, null);
|
|
103
|
+
return;
|
|
104
|
+
} catch (Exception e) {
|
|
105
|
+
String msg = "IsStoreOpen: " + e.getMessage();
|
|
106
|
+
rHandler.retResult(call, false, msg);
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
@PluginMethod
|
|
112
|
+
public void isStoreExists(PluginCall call) {
|
|
113
|
+
boolean ret = false;
|
|
114
|
+
if (!call.getData().has("database")) {
|
|
115
|
+
rHandler.retResult(call, false, "IsStoreExists: Must provide a database");
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
String dbName = call.getString("database");
|
|
119
|
+
try {
|
|
120
|
+
ret = implementation.isStoreExists(dbName);
|
|
121
|
+
rHandler.retResult(call, ret, null);
|
|
122
|
+
return;
|
|
123
|
+
} catch (Exception e) {
|
|
124
|
+
String msg = "IsStoreExists: " + e.getMessage();
|
|
125
|
+
rHandler.retResult(call, false, msg);
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
@PluginMethod
|
|
131
|
+
public void set(PluginCall call) {
|
|
132
|
+
if (!call.getData().has("key")) {
|
|
133
|
+
rHandler.retResult(call, null, "Set: Must provide a key");
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
136
|
+
String key = call.getString("key");
|
|
137
|
+
if (!call.getData().has("value")) {
|
|
138
|
+
rHandler.retResult(call, null, "Set: Must provide a value");
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
141
|
+
String value = call.getString("value");
|
|
142
|
+
try {
|
|
143
|
+
implementation.set(key, value);
|
|
144
|
+
rHandler.retResult(call, null, null);
|
|
145
|
+
return;
|
|
146
|
+
} catch (Exception e) {
|
|
147
|
+
String msg = "Set: " + e.getMessage();
|
|
148
|
+
rHandler.retResult(call, null, msg);
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
@PluginMethod
|
|
154
|
+
public void get(PluginCall call) {
|
|
155
|
+
if (!call.getData().has("key")) {
|
|
156
|
+
rHandler.retValue(call, null, "Get: Must provide a key");
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
159
|
+
String key = call.getString("key");
|
|
160
|
+
try {
|
|
161
|
+
String value = implementation.get(key);
|
|
162
|
+
rHandler.retValue(call, value, null);
|
|
163
|
+
return;
|
|
164
|
+
} catch (Exception e) {
|
|
165
|
+
String msg = "Get: " + e.getMessage();
|
|
166
|
+
rHandler.retValue(call, null, msg);
|
|
167
|
+
return;
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
@PluginMethod
|
|
172
|
+
public void remove(PluginCall call) {
|
|
173
|
+
if (!call.getData().has("key")) {
|
|
174
|
+
rHandler.retResult(call, null, "Remove: Must provide a key");
|
|
175
|
+
return;
|
|
176
|
+
}
|
|
177
|
+
String key = call.getString("key");
|
|
178
|
+
try {
|
|
179
|
+
implementation.remove(key);
|
|
180
|
+
rHandler.retResult(call, null, null);
|
|
181
|
+
return;
|
|
182
|
+
} catch (Exception e) {
|
|
183
|
+
String msg = "Remove: " + e.getMessage();
|
|
184
|
+
rHandler.retResult(call, null, msg);
|
|
185
|
+
return;
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
@PluginMethod
|
|
190
|
+
public void clear(PluginCall call) {
|
|
191
|
+
try {
|
|
192
|
+
implementation.clear();
|
|
193
|
+
rHandler.retResult(call, null, null);
|
|
194
|
+
return;
|
|
195
|
+
} catch (Exception e) {
|
|
196
|
+
String msg = "Clear: " + e.getMessage();
|
|
197
|
+
rHandler.retResult(call, null, msg);
|
|
198
|
+
return;
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
@PluginMethod
|
|
203
|
+
public void iskey(PluginCall call) {
|
|
204
|
+
boolean ret = false;
|
|
205
|
+
if (!call.getData().has("key")) {
|
|
206
|
+
rHandler.retResult(call, false, "Iskey: Must provide a key");
|
|
207
|
+
return;
|
|
208
|
+
}
|
|
209
|
+
String key = call.getString("key");
|
|
210
|
+
try {
|
|
211
|
+
ret = implementation.iskey(key);
|
|
212
|
+
rHandler.retResult(call, ret, null);
|
|
213
|
+
return;
|
|
214
|
+
} catch (Exception e) {
|
|
215
|
+
String msg = "Iskey: " + e.getMessage();
|
|
216
|
+
rHandler.retResult(call, false, msg);
|
|
217
|
+
return;
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
@PluginMethod
|
|
222
|
+
public void keys(PluginCall call) {
|
|
223
|
+
try {
|
|
224
|
+
String[] keyArray = implementation.keys();
|
|
225
|
+
JSObject ret = new JSObject();
|
|
226
|
+
ret.put("keys", new JSArray(keyArray));
|
|
227
|
+
rHandler.retJSObject(call, ret, null);
|
|
228
|
+
return;
|
|
229
|
+
} catch (Exception e) {
|
|
230
|
+
String msg = "Keys: " + e.getMessage();
|
|
231
|
+
rHandler.retJSObject(call, new JSObject(), msg);
|
|
232
|
+
return;
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
@PluginMethod
|
|
237
|
+
public void values(PluginCall call) {
|
|
238
|
+
try {
|
|
239
|
+
String[] valueArray = implementation.values();
|
|
240
|
+
JSObject ret = new JSObject();
|
|
241
|
+
ret.put("values", new JSArray(valueArray));
|
|
242
|
+
rHandler.retJSObject(call, ret, null);
|
|
243
|
+
return;
|
|
244
|
+
} catch (Exception e) {
|
|
245
|
+
String msg = "Values: " + e.getMessage();
|
|
246
|
+
rHandler.retJSObject(call, new JSObject(), msg);
|
|
247
|
+
return;
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
@PluginMethod
|
|
252
|
+
public void keysvalues(PluginCall call) {
|
|
253
|
+
try {
|
|
254
|
+
JSObject[] jsObjArray = implementation.keysvalues();
|
|
255
|
+
JSObject ret = new JSObject();
|
|
256
|
+
ret.put("keysvalues", new JSArray(jsObjArray));
|
|
257
|
+
rHandler.retJSObject(call, ret, null);
|
|
258
|
+
return;
|
|
259
|
+
} catch (Exception e) {
|
|
260
|
+
String msg = "KeysValues: " + e.getMessage();
|
|
261
|
+
rHandler.retJSObject(call, new JSObject(), msg);
|
|
262
|
+
return;
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
@PluginMethod
|
|
267
|
+
public void filtervalues(PluginCall call) {
|
|
268
|
+
if (!call.getData().has("filter")) {
|
|
269
|
+
rHandler.retJSObject(
|
|
270
|
+
call,
|
|
271
|
+
new JSObject(),
|
|
272
|
+
"Filtervalues: Must provide a filter"
|
|
273
|
+
);
|
|
274
|
+
return;
|
|
275
|
+
}
|
|
276
|
+
String filter = call.getString("filter");
|
|
277
|
+
try {
|
|
278
|
+
String[] valueArray = implementation.filtervalues(filter);
|
|
279
|
+
JSObject ret = new JSObject();
|
|
280
|
+
ret.put("values", new JSArray(valueArray));
|
|
281
|
+
rHandler.retJSObject(call, ret, null);
|
|
282
|
+
return;
|
|
283
|
+
} catch (Exception e) {
|
|
284
|
+
String msg = "Filtervalues: " + e.getMessage();
|
|
285
|
+
rHandler.retJSObject(call, new JSObject(), msg);
|
|
286
|
+
return;
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
@PluginMethod
|
|
291
|
+
public void setTable(PluginCall call) {
|
|
292
|
+
if (!call.getData().has("table")) {
|
|
293
|
+
rHandler.retResult(call, false, "SetTable: Must provide a table");
|
|
294
|
+
return;
|
|
295
|
+
}
|
|
296
|
+
String table = call.getString("table");
|
|
297
|
+
try {
|
|
298
|
+
implementation.setTable(table);
|
|
299
|
+
rHandler.retResult(call, null, null);
|
|
300
|
+
return;
|
|
301
|
+
} catch (Exception e) {
|
|
302
|
+
String msg = "SetTable: " + e.getMessage();
|
|
303
|
+
rHandler.retResult(call, null, msg);
|
|
304
|
+
return;
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
@PluginMethod
|
|
309
|
+
public void isTable(PluginCall call) {
|
|
310
|
+
boolean ret = false;
|
|
311
|
+
if (!call.getData().has("table")) {
|
|
312
|
+
rHandler.retResult(call, false, "IsTable: Must provide a table");
|
|
313
|
+
return;
|
|
314
|
+
}
|
|
315
|
+
String table = call.getString("table");
|
|
316
|
+
try {
|
|
317
|
+
ret = implementation.isTable(table);
|
|
318
|
+
rHandler.retResult(call, ret, null);
|
|
319
|
+
return;
|
|
320
|
+
} catch (Exception e) {
|
|
321
|
+
String msg = "IsTable: " + e.getMessage();
|
|
322
|
+
rHandler.retResult(call, false, msg);
|
|
323
|
+
return;
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
@PluginMethod
|
|
328
|
+
public void tables(PluginCall call) {
|
|
329
|
+
try {
|
|
330
|
+
String[] tableArray = implementation.tables();
|
|
331
|
+
JSObject ret = new JSObject();
|
|
332
|
+
ret.put("tables", new JSArray(tableArray));
|
|
333
|
+
rHandler.retJSObject(call, ret, null);
|
|
334
|
+
return;
|
|
335
|
+
} catch (Exception e) {
|
|
336
|
+
String msg = "Tables: " + e.getMessage();
|
|
337
|
+
rHandler.retJSObject(call, new JSObject(), msg);
|
|
338
|
+
return;
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
@PluginMethod
|
|
343
|
+
public void deleteTable(PluginCall call) {
|
|
344
|
+
if (!call.getData().has("table")) {
|
|
345
|
+
rHandler.retResult(call, null, "DeleteTable: Must provide a table");
|
|
346
|
+
return;
|
|
347
|
+
}
|
|
348
|
+
String table = call.getString("table");
|
|
349
|
+
try {
|
|
350
|
+
implementation.deleteTable(table);
|
|
351
|
+
rHandler.retResult(call, null, null);
|
|
352
|
+
return;
|
|
353
|
+
} catch (Exception e) {
|
|
354
|
+
String msg = "DeleteTable: " + e.getMessage();
|
|
355
|
+
rHandler.retResult(call, null, msg);
|
|
356
|
+
return;
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
@PluginMethod
|
|
361
|
+
public void deleteStore(PluginCall call) {
|
|
362
|
+
if (!call.getData().has("database")) {
|
|
363
|
+
rHandler.retResult(call, null, "DeleteStore: Must provide a database");
|
|
364
|
+
return;
|
|
365
|
+
}
|
|
366
|
+
String dbName = call.getString("database");
|
|
367
|
+
try {
|
|
368
|
+
implementation.deleteStore(dbName);
|
|
369
|
+
rHandler.retResult(call, null, null);
|
|
370
|
+
return;
|
|
371
|
+
} catch (Exception e) {
|
|
372
|
+
String msg = "DeleteStore: " + e.getMessage();
|
|
373
|
+
rHandler.retResult(call, null, msg);
|
|
374
|
+
return;
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
/**
|
|
379
|
+
* IsJsonValid
|
|
380
|
+
* Check the validity of a given Json object
|
|
381
|
+
* @param call
|
|
382
|
+
*/
|
|
383
|
+
@PluginMethod
|
|
384
|
+
public void isJsonValid(PluginCall call) {
|
|
385
|
+
if (!call.getData().has("jsonstring")) {
|
|
386
|
+
String msg = "IsJsonValid: Must provide a Stringify Json Object";
|
|
387
|
+
rHandler.retResult(call, false, msg);
|
|
388
|
+
return;
|
|
389
|
+
}
|
|
390
|
+
String parsingData = call.getString("jsonstring");
|
|
391
|
+
try {
|
|
392
|
+
Boolean res = implementation.isJsonValid(parsingData);
|
|
393
|
+
rHandler.retResult(call, res, null);
|
|
394
|
+
return;
|
|
395
|
+
} catch (Exception e) {
|
|
396
|
+
String msg = "isJsonValid: " + e.getMessage();
|
|
397
|
+
rHandler.retResult(call, false, msg);
|
|
398
|
+
return;
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
/**
|
|
403
|
+
* ImportFromJson Method
|
|
404
|
+
* Import from a given Json object
|
|
405
|
+
* @param call
|
|
406
|
+
*/
|
|
407
|
+
@PluginMethod
|
|
408
|
+
public void importFromJson(PluginCall call) {
|
|
409
|
+
JSObject retRes = new JSObject();
|
|
410
|
+
retRes.put("changes", Integer.valueOf(-1));
|
|
411
|
+
if (!call.getData().has("jsonstring")) {
|
|
412
|
+
String msg = "ImportFromJson: Must provide a Stringify Json Object";
|
|
413
|
+
rHandler.retChanges(call, retRes, msg);
|
|
414
|
+
return;
|
|
415
|
+
}
|
|
416
|
+
String parsingData = call.getString("jsonstring");
|
|
417
|
+
try {
|
|
418
|
+
JSObject res = implementation.importFromJson(parsingData);
|
|
419
|
+
rHandler.retChanges(call, res, null);
|
|
420
|
+
return;
|
|
421
|
+
} catch (Exception e) {
|
|
422
|
+
String msg = "ImportFromJson: " + e.getMessage();
|
|
423
|
+
rHandler.retChanges(call, retRes, msg);
|
|
424
|
+
return;
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
/**
|
|
429
|
+
* ExportToJson Method
|
|
430
|
+
* Export the database to Json Object
|
|
431
|
+
* @param call
|
|
432
|
+
*/
|
|
433
|
+
@PluginMethod
|
|
434
|
+
public void exportToJson(PluginCall call) {
|
|
435
|
+
JSObject retObj = new JSObject();
|
|
436
|
+
|
|
437
|
+
try {
|
|
438
|
+
JSObject res = implementation.exportToJson();
|
|
439
|
+
rHandler.retJsonObject(call, res, null);
|
|
440
|
+
return;
|
|
441
|
+
} catch (Exception e) {
|
|
442
|
+
String msg = "ExportToJson: " + e.getMessage();
|
|
443
|
+
rHandler.retJsonObject(call, retObj, msg);
|
|
444
|
+
return;
|
|
445
|
+
}
|
|
446
|
+
}
|
|
447
|
+
}
|
package/android/src/main/java/com/jeep/plugin/capacitor/capacitordatastoragesqlite/RetHandler.java
ADDED
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
package com.jeep.plugin.capacitor.capacitordatastoragesqlite;
|
|
2
|
+
|
|
3
|
+
import android.util.Log;
|
|
4
|
+
import com.getcapacitor.JSArray;
|
|
5
|
+
import com.getcapacitor.JSObject;
|
|
6
|
+
import com.getcapacitor.PluginCall;
|
|
7
|
+
|
|
8
|
+
public class RetHandler {
|
|
9
|
+
|
|
10
|
+
private static final String TAG = RetHandler.class.getName();
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* RetResult Method
|
|
14
|
+
* Create and return the capSQLiteResult object
|
|
15
|
+
*
|
|
16
|
+
* @param call
|
|
17
|
+
* @param res
|
|
18
|
+
* @param message
|
|
19
|
+
*/
|
|
20
|
+
public void retResult(PluginCall call, Boolean res, String message) {
|
|
21
|
+
JSObject ret = new JSObject();
|
|
22
|
+
if (message != null) {
|
|
23
|
+
ret.put("message", message);
|
|
24
|
+
Log.v(TAG, "*** ERROR " + message);
|
|
25
|
+
call.reject(message);
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
if (res != null) {
|
|
29
|
+
ret.put("result", res);
|
|
30
|
+
call.resolve(ret);
|
|
31
|
+
return;
|
|
32
|
+
} else {
|
|
33
|
+
call.resolve();
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* RetValue Method
|
|
40
|
+
* Create and return a value
|
|
41
|
+
* @param call
|
|
42
|
+
* @param res
|
|
43
|
+
* @param message
|
|
44
|
+
*/
|
|
45
|
+
public void retValue(PluginCall call, String res, String message) {
|
|
46
|
+
JSObject ret = new JSObject();
|
|
47
|
+
if (message != null) {
|
|
48
|
+
ret.put("message", message);
|
|
49
|
+
Log.v(TAG, "*** ERROR " + message);
|
|
50
|
+
call.reject(message);
|
|
51
|
+
return;
|
|
52
|
+
} else {
|
|
53
|
+
ret.put("value", res);
|
|
54
|
+
call.resolve(ret);
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* RetJSObject Method
|
|
61
|
+
* Create and return the capSQLiteJson object
|
|
62
|
+
* @param call
|
|
63
|
+
* @param res
|
|
64
|
+
* @param message
|
|
65
|
+
*/
|
|
66
|
+
public void retJSObject(PluginCall call, JSObject res, String message) {
|
|
67
|
+
if (message != null) {
|
|
68
|
+
call.reject(message);
|
|
69
|
+
return;
|
|
70
|
+
} else {
|
|
71
|
+
call.resolve(res);
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* RetChanges Method
|
|
78
|
+
* Create and return the capSQLiteChanges object
|
|
79
|
+
* @param call
|
|
80
|
+
* @param res
|
|
81
|
+
* @param message
|
|
82
|
+
*/
|
|
83
|
+
public void retChanges(PluginCall call, JSObject res, String message) {
|
|
84
|
+
JSObject ret = new JSObject();
|
|
85
|
+
if (message != null) {
|
|
86
|
+
ret.put("message", message);
|
|
87
|
+
Log.v(TAG, "*** ERROR " + message);
|
|
88
|
+
call.reject(message);
|
|
89
|
+
return;
|
|
90
|
+
} else {
|
|
91
|
+
ret.put("changes", res);
|
|
92
|
+
call.resolve(ret);
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* RetJSObject Method
|
|
99
|
+
* Create and return the capSQLiteJson object
|
|
100
|
+
* @param call
|
|
101
|
+
* @param res
|
|
102
|
+
* @param message
|
|
103
|
+
*/
|
|
104
|
+
public void retJsonObject(PluginCall call, JSObject res, String message) {
|
|
105
|
+
JSObject ret = new JSObject();
|
|
106
|
+
if (message != null) {
|
|
107
|
+
ret.put("message", message);
|
|
108
|
+
Log.v(TAG, "*** ERROR " + message);
|
|
109
|
+
call.reject(message);
|
|
110
|
+
return;
|
|
111
|
+
} else {
|
|
112
|
+
ret.put("export", res);
|
|
113
|
+
call.resolve(ret);
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
package com.jeep.plugin.capacitor.capacitordatastoragesqlite.cdssUtils.ImportExportJson;
|
|
2
|
+
|
|
3
|
+
import android.util.Log;
|
|
4
|
+
import com.getcapacitor.JSArray;
|
|
5
|
+
import com.getcapacitor.JSObject;
|
|
6
|
+
import java.util.ArrayList;
|
|
7
|
+
import java.util.Arrays;
|
|
8
|
+
import java.util.Iterator;
|
|
9
|
+
import java.util.List;
|
|
10
|
+
import org.json.JSONArray;
|
|
11
|
+
import org.json.JSONException;
|
|
12
|
+
|
|
13
|
+
public class JsonStore {
|
|
14
|
+
|
|
15
|
+
private static final String TAG = "JsonStore";
|
|
16
|
+
|
|
17
|
+
private String database = "";
|
|
18
|
+
private Boolean encrypted = null;
|
|
19
|
+
private ArrayList<JsonTable> tables = new ArrayList<JsonTable>();
|
|
20
|
+
|
|
21
|
+
private static final List<String> keyFirstLevel = new ArrayList<String>(
|
|
22
|
+
Arrays.asList("database", "encrypted", "tables")
|
|
23
|
+
);
|
|
24
|
+
|
|
25
|
+
// Getter
|
|
26
|
+
public String getDatabase() {
|
|
27
|
+
return database;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
public Boolean getEncrypted() {
|
|
31
|
+
return encrypted;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
public ArrayList<JsonTable> getTables() {
|
|
35
|
+
return tables;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// Setter
|
|
39
|
+
public void setDatabase(String newDatabase) {
|
|
40
|
+
this.database = newDatabase;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
public void setEncrypted(Boolean newEncrypted) {
|
|
44
|
+
this.encrypted = newEncrypted;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
public void setTables(ArrayList<JsonTable> newTables) {
|
|
48
|
+
this.tables = newTables;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
public ArrayList<String> getKeys() {
|
|
52
|
+
ArrayList<String> retArray = new ArrayList<String>();
|
|
53
|
+
if (getDatabase().length() > 0) retArray.add("database");
|
|
54
|
+
if (getEncrypted() != null) retArray.add("encrypted");
|
|
55
|
+
if (getTables().size() > 0) retArray.add("tables");
|
|
56
|
+
return retArray;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
public boolean isJsonStore(JSObject jsObj) {
|
|
60
|
+
if (jsObj == null || jsObj.length() == 0) return false;
|
|
61
|
+
Iterator<String> keys = jsObj.keys();
|
|
62
|
+
while (keys.hasNext()) {
|
|
63
|
+
String key = keys.next();
|
|
64
|
+
if (!keyFirstLevel.contains(key)) return false;
|
|
65
|
+
try {
|
|
66
|
+
Object value = jsObj.get(key);
|
|
67
|
+
|
|
68
|
+
if (key.equals("database")) {
|
|
69
|
+
if (!(value instanceof String)) {
|
|
70
|
+
return false;
|
|
71
|
+
} else {
|
|
72
|
+
database = (String) value;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
if (key.equals("encrypted")) {
|
|
76
|
+
if (!(value instanceof Boolean)) {
|
|
77
|
+
return false;
|
|
78
|
+
} else {
|
|
79
|
+
encrypted = jsObj.getBool(key);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
if (key.equals("tables")) {
|
|
83
|
+
if (!(value instanceof JSONArray)) {
|
|
84
|
+
String msg = "value: not instance of JSONArray 1";
|
|
85
|
+
Log.d(TAG, msg);
|
|
86
|
+
|
|
87
|
+
return false;
|
|
88
|
+
} else {
|
|
89
|
+
if (value instanceof JSONArray) {
|
|
90
|
+
JSONArray arrJS = jsObj.getJSONArray(key);
|
|
91
|
+
tables = new ArrayList<>();
|
|
92
|
+
|
|
93
|
+
for (int i = 0; i < arrJS.length(); i++) {
|
|
94
|
+
JsonTable table = new JsonTable();
|
|
95
|
+
boolean retTable = table.isTable(arrJS.getJSONObject(i));
|
|
96
|
+
|
|
97
|
+
if (!retTable) return false;
|
|
98
|
+
tables.add(table);
|
|
99
|
+
}
|
|
100
|
+
} else {
|
|
101
|
+
String msg = "value: not instance of ";
|
|
102
|
+
msg += "JSONArray 2";
|
|
103
|
+
Log.d(TAG, msg);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
} catch (JSONException e) {
|
|
108
|
+
e.printStackTrace();
|
|
109
|
+
return false;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
return true;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
public void print() {
|
|
116
|
+
Log.d(TAG, "database: " + this.getDatabase());
|
|
117
|
+
Log.d(TAG, "encrypted: " + this.getEncrypted());
|
|
118
|
+
Log.d(TAG, "number of Tables: " + this.getTables().size());
|
|
119
|
+
for (JsonTable table : this.getTables()) {
|
|
120
|
+
table.print();
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
public JSArray getTablesAsJSObject() {
|
|
125
|
+
JSArray JSTables = new JSArray();
|
|
126
|
+
for (JsonTable table : this.tables) {
|
|
127
|
+
JSTables.put(table.getTableAsJSObject());
|
|
128
|
+
}
|
|
129
|
+
return JSTables;
|
|
130
|
+
}
|
|
131
|
+
}
|