CordovaArgs.java 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /*
  2. Licensed to the Apache Software Foundation (ASF) under one
  3. or more contributor license agreements. See the NOTICE file
  4. distributed with this work for additional information
  5. regarding copyright ownership. The ASF licenses this file
  6. to you under the Apache License, Version 2.0 (the
  7. "License"); you may not use this file except in compliance
  8. with the License. You may obtain a copy of the License at
  9. http://www.apache.org/licenses/LICENSE-2.0
  10. Unless required by applicable law or agreed to in writing,
  11. software distributed under the License is distributed on an
  12. "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  13. KIND, either express or implied. See the License for the
  14. specific language governing permissions and limitations
  15. under the License.
  16. */
  17. package org.apache.cordova;
  18. import org.json.JSONArray;
  19. import org.json.JSONException;
  20. import org.json.JSONObject;
  21. import android.util.Base64;
  22. public class CordovaArgs {
  23. private JSONArray baseArgs;
  24. public CordovaArgs(JSONArray args) {
  25. this.baseArgs = args;
  26. }
  27. // Pass through the basics to the base args.
  28. public Object get(int index) throws JSONException {
  29. return baseArgs.get(index);
  30. }
  31. public boolean getBoolean(int index) throws JSONException {
  32. return baseArgs.getBoolean(index);
  33. }
  34. public double getDouble(int index) throws JSONException {
  35. return baseArgs.getDouble(index);
  36. }
  37. public int getInt(int index) throws JSONException {
  38. return baseArgs.getInt(index);
  39. }
  40. public JSONArray getJSONArray(int index) throws JSONException {
  41. return baseArgs.getJSONArray(index);
  42. }
  43. public JSONObject getJSONObject(int index) throws JSONException {
  44. return baseArgs.getJSONObject(index);
  45. }
  46. public long getLong(int index) throws JSONException {
  47. return baseArgs.getLong(index);
  48. }
  49. public String getString(int index) throws JSONException {
  50. return baseArgs.getString(index);
  51. }
  52. public Object opt(int index) {
  53. return baseArgs.opt(index);
  54. }
  55. public boolean optBoolean(int index) {
  56. return baseArgs.optBoolean(index);
  57. }
  58. public double optDouble(int index) {
  59. return baseArgs.optDouble(index);
  60. }
  61. public int optInt(int index) {
  62. return baseArgs.optInt(index);
  63. }
  64. public JSONArray optJSONArray(int index) {
  65. return baseArgs.optJSONArray(index);
  66. }
  67. public JSONObject optJSONObject(int index) {
  68. return baseArgs.optJSONObject(index);
  69. }
  70. public long optLong(int index) {
  71. return baseArgs.optLong(index);
  72. }
  73. public String optString(int index) {
  74. return baseArgs.optString(index);
  75. }
  76. public boolean isNull(int index) {
  77. return baseArgs.isNull(index);
  78. }
  79. // The interesting custom helpers.
  80. public byte[] getArrayBuffer(int index) throws JSONException {
  81. String encoded = baseArgs.getString(index);
  82. return Base64.decode(encoded, Base64.DEFAULT);
  83. }
  84. }