The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1 | /* //device/libs/android_runtime/android_util_XmlBlock.cpp |
| 2 | ** |
| 3 | ** Copyright 2006, The Android Open Source Project |
| 4 | ** |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 5 | ** Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | ** you may not use this file except in compliance with the License. |
| 7 | ** You may obtain a copy of the License at |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8 | ** |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 9 | ** http://www.apache.org/licenses/LICENSE-2.0 |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10 | ** |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 11 | ** Unless required by applicable law or agreed to in writing, software |
| 12 | ** distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | ** See the License for the specific language governing permissions and |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15 | ** limitations under the License. |
| 16 | */ |
| 17 | |
| 18 | #define LOG_TAG "XmlBlock" |
| 19 | |
| 20 | #include "jni.h" |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 21 | #include "JNIHelp.h" |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 22 | #include <android_runtime/AndroidRuntime.h> |
Mathias Agopian | b13b9bd | 2012-02-17 18:27:36 -0800 | [diff] [blame] | 23 | #include <androidfw/AssetManager.h> |
| 24 | #include <androidfw/ResourceTypes.h> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 25 | #include <utils/Log.h> |
Mathias Agopian | b13b9bd | 2012-02-17 18:27:36 -0800 | [diff] [blame] | 26 | #include <utils/misc.h> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 27 | |
| 28 | #include <stdio.h> |
| 29 | |
| 30 | namespace android { |
| 31 | |
| 32 | // ---------------------------------------------------------------------------- |
| 33 | |
Ashok Bhat | 896043d | 2014-01-17 16:02:38 +0000 | [diff] [blame^] | 34 | static jlong android_content_XmlBlock_nativeCreate(JNIEnv* env, jobject clazz, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 35 | jbyteArray bArray, |
| 36 | jint off, jint len) |
| 37 | { |
| 38 | if (bArray == NULL) { |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 39 | jniThrowNullPointerException(env, NULL); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 40 | return 0; |
| 41 | } |
| 42 | |
| 43 | jsize bLen = env->GetArrayLength(bArray); |
| 44 | if (off < 0 || off >= bLen || len < 0 || len > bLen || (off+len) > bLen) { |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 45 | jniThrowException(env, "java/lang/IndexOutOfBoundsException", NULL); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 46 | return 0; |
| 47 | } |
| 48 | |
| 49 | jbyte* b = env->GetByteArrayElements(bArray, NULL); |
| 50 | ResXMLTree* osb = new ResXMLTree(b+off, len, true); |
| 51 | env->ReleaseByteArrayElements(bArray, b, 0); |
| 52 | |
| 53 | if (osb == NULL || osb->getError() != NO_ERROR) { |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 54 | jniThrowException(env, "java/lang/IllegalArgumentException", NULL); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 55 | return 0; |
| 56 | } |
| 57 | |
Ashok Bhat | 896043d | 2014-01-17 16:02:38 +0000 | [diff] [blame^] | 58 | return reinterpret_cast<jlong>(osb); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 59 | } |
| 60 | |
Ashok Bhat | 896043d | 2014-01-17 16:02:38 +0000 | [diff] [blame^] | 61 | static jlong android_content_XmlBlock_nativeGetStringBlock(JNIEnv* env, jobject clazz, |
| 62 | jlong token) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 63 | { |
Ashok Bhat | 896043d | 2014-01-17 16:02:38 +0000 | [diff] [blame^] | 64 | ResXMLTree* osb = reinterpret_cast<ResXMLTree*>(token); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 65 | if (osb == NULL) { |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 66 | jniThrowNullPointerException(env, NULL); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 67 | return 0; |
| 68 | } |
| 69 | |
Ashok Bhat | 896043d | 2014-01-17 16:02:38 +0000 | [diff] [blame^] | 70 | return reinterpret_cast<jlong>(&osb->getStrings()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 71 | } |
| 72 | |
Ashok Bhat | 896043d | 2014-01-17 16:02:38 +0000 | [diff] [blame^] | 73 | static jlong android_content_XmlBlock_nativeCreateParseState(JNIEnv* env, jobject clazz, |
| 74 | jlong token) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 75 | { |
Ashok Bhat | 896043d | 2014-01-17 16:02:38 +0000 | [diff] [blame^] | 76 | ResXMLTree* osb = reinterpret_cast<ResXMLTree*>(token); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 77 | if (osb == NULL) { |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 78 | jniThrowNullPointerException(env, NULL); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 79 | return 0; |
| 80 | } |
| 81 | |
| 82 | ResXMLParser* st = new ResXMLParser(*osb); |
| 83 | if (st == NULL) { |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 84 | jniThrowException(env, "java/lang/OutOfMemoryError", NULL); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 85 | return 0; |
| 86 | } |
| 87 | |
| 88 | st->restart(); |
| 89 | |
Ashok Bhat | 896043d | 2014-01-17 16:02:38 +0000 | [diff] [blame^] | 90 | return reinterpret_cast<jlong>(st); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 91 | } |
| 92 | |
| 93 | static jint android_content_XmlBlock_nativeNext(JNIEnv* env, jobject clazz, |
Ashok Bhat | 896043d | 2014-01-17 16:02:38 +0000 | [diff] [blame^] | 94 | jlong token) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 95 | { |
Ashok Bhat | 896043d | 2014-01-17 16:02:38 +0000 | [diff] [blame^] | 96 | ResXMLParser* st = reinterpret_cast<ResXMLParser*>(token); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 97 | if (st == NULL) { |
| 98 | return ResXMLParser::END_DOCUMENT; |
| 99 | } |
| 100 | |
| 101 | do { |
Ashok Bhat | 896043d | 2014-01-17 16:02:38 +0000 | [diff] [blame^] | 102 | ResXMLParser::event_code_t code = st->next(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 103 | switch (code) { |
| 104 | case ResXMLParser::START_TAG: |
| 105 | return 2; |
| 106 | case ResXMLParser::END_TAG: |
| 107 | return 3; |
| 108 | case ResXMLParser::TEXT: |
| 109 | return 4; |
| 110 | case ResXMLParser::START_DOCUMENT: |
| 111 | return 0; |
| 112 | case ResXMLParser::END_DOCUMENT: |
| 113 | return 1; |
| 114 | case ResXMLParser::BAD_DOCUMENT: |
| 115 | goto bad; |
| 116 | } |
| 117 | } while (true); |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 118 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 119 | bad: |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 120 | jniThrowException(env, "org/xmlpull/v1/XmlPullParserException", |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 121 | "Corrupt XML binary file"); |
| 122 | return ResXMLParser::BAD_DOCUMENT; |
| 123 | } |
| 124 | |
| 125 | static jint android_content_XmlBlock_nativeGetNamespace(JNIEnv* env, jobject clazz, |
Ashok Bhat | 896043d | 2014-01-17 16:02:38 +0000 | [diff] [blame^] | 126 | jlong token) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 127 | { |
Ashok Bhat | 896043d | 2014-01-17 16:02:38 +0000 | [diff] [blame^] | 128 | ResXMLParser* st = reinterpret_cast<ResXMLParser*>(token); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 129 | if (st == NULL) { |
| 130 | return -1; |
| 131 | } |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 132 | |
Ashok Bhat | 896043d | 2014-01-17 16:02:38 +0000 | [diff] [blame^] | 133 | return static_cast<jint>(st->getElementNamespaceID()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 134 | } |
| 135 | |
| 136 | static jint android_content_XmlBlock_nativeGetName(JNIEnv* env, jobject clazz, |
Ashok Bhat | 896043d | 2014-01-17 16:02:38 +0000 | [diff] [blame^] | 137 | jlong token) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 138 | { |
Ashok Bhat | 896043d | 2014-01-17 16:02:38 +0000 | [diff] [blame^] | 139 | ResXMLParser* st = reinterpret_cast<ResXMLParser*>(token); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 140 | if (st == NULL) { |
| 141 | return -1; |
| 142 | } |
| 143 | |
Ashok Bhat | 896043d | 2014-01-17 16:02:38 +0000 | [diff] [blame^] | 144 | return static_cast<jint>(st->getElementNameID()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 145 | } |
| 146 | |
| 147 | static jint android_content_XmlBlock_nativeGetText(JNIEnv* env, jobject clazz, |
Ashok Bhat | 896043d | 2014-01-17 16:02:38 +0000 | [diff] [blame^] | 148 | jlong token) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 149 | { |
Ashok Bhat | 896043d | 2014-01-17 16:02:38 +0000 | [diff] [blame^] | 150 | ResXMLParser* st = reinterpret_cast<ResXMLParser*>(token); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 151 | if (st == NULL) { |
| 152 | return -1; |
| 153 | } |
| 154 | |
Ashok Bhat | 896043d | 2014-01-17 16:02:38 +0000 | [diff] [blame^] | 155 | return static_cast<jint>(st->getTextID()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 156 | } |
| 157 | |
| 158 | static jint android_content_XmlBlock_nativeGetLineNumber(JNIEnv* env, jobject clazz, |
Ashok Bhat | 896043d | 2014-01-17 16:02:38 +0000 | [diff] [blame^] | 159 | jlong token) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 160 | { |
Ashok Bhat | 896043d | 2014-01-17 16:02:38 +0000 | [diff] [blame^] | 161 | ResXMLParser* st = reinterpret_cast<ResXMLParser*>(token); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 162 | if (st == NULL) { |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 163 | jniThrowNullPointerException(env, NULL); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 164 | return 0; |
| 165 | } |
| 166 | |
Ashok Bhat | 896043d | 2014-01-17 16:02:38 +0000 | [diff] [blame^] | 167 | return static_cast<jint>(st->getLineNumber()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 168 | } |
| 169 | |
| 170 | static jint android_content_XmlBlock_nativeGetAttributeCount(JNIEnv* env, jobject clazz, |
Ashok Bhat | 896043d | 2014-01-17 16:02:38 +0000 | [diff] [blame^] | 171 | jlong token) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 172 | { |
Ashok Bhat | 896043d | 2014-01-17 16:02:38 +0000 | [diff] [blame^] | 173 | ResXMLParser* st = reinterpret_cast<ResXMLParser*>(token); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 174 | if (st == NULL) { |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 175 | jniThrowNullPointerException(env, NULL); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 176 | return 0; |
| 177 | } |
| 178 | |
Ashok Bhat | 896043d | 2014-01-17 16:02:38 +0000 | [diff] [blame^] | 179 | return static_cast<jint>(st->getAttributeCount()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 180 | } |
| 181 | |
| 182 | static jint android_content_XmlBlock_nativeGetAttributeNamespace(JNIEnv* env, jobject clazz, |
Ashok Bhat | 896043d | 2014-01-17 16:02:38 +0000 | [diff] [blame^] | 183 | jlong token, jint idx) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 184 | { |
Ashok Bhat | 896043d | 2014-01-17 16:02:38 +0000 | [diff] [blame^] | 185 | ResXMLParser* st = reinterpret_cast<ResXMLParser*>(token); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 186 | if (st == NULL) { |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 187 | jniThrowNullPointerException(env, NULL); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 188 | return 0; |
| 189 | } |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 190 | |
Ashok Bhat | 896043d | 2014-01-17 16:02:38 +0000 | [diff] [blame^] | 191 | return static_cast<jint>(st->getAttributeNamespaceID(idx)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 192 | } |
| 193 | |
| 194 | static jint android_content_XmlBlock_nativeGetAttributeName(JNIEnv* env, jobject clazz, |
Ashok Bhat | 896043d | 2014-01-17 16:02:38 +0000 | [diff] [blame^] | 195 | jlong token, jint idx) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 196 | { |
Ashok Bhat | 896043d | 2014-01-17 16:02:38 +0000 | [diff] [blame^] | 197 | ResXMLParser* st = reinterpret_cast<ResXMLParser*>(token); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 198 | if (st == NULL) { |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 199 | jniThrowNullPointerException(env, NULL); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 200 | return 0; |
| 201 | } |
| 202 | |
Ashok Bhat | 896043d | 2014-01-17 16:02:38 +0000 | [diff] [blame^] | 203 | return static_cast<jint>(st->getAttributeNameID(idx)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 204 | } |
| 205 | |
| 206 | static jint android_content_XmlBlock_nativeGetAttributeResource(JNIEnv* env, jobject clazz, |
Ashok Bhat | 896043d | 2014-01-17 16:02:38 +0000 | [diff] [blame^] | 207 | jlong token, jint idx) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 208 | { |
Ashok Bhat | 896043d | 2014-01-17 16:02:38 +0000 | [diff] [blame^] | 209 | ResXMLParser* st = reinterpret_cast<ResXMLParser*>(token); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 210 | if (st == NULL) { |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 211 | jniThrowNullPointerException(env, NULL); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 212 | return 0; |
| 213 | } |
| 214 | |
Ashok Bhat | 896043d | 2014-01-17 16:02:38 +0000 | [diff] [blame^] | 215 | return static_cast<jint>(st->getAttributeNameResID(idx)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 216 | } |
| 217 | |
| 218 | static jint android_content_XmlBlock_nativeGetAttributeDataType(JNIEnv* env, jobject clazz, |
Ashok Bhat | 896043d | 2014-01-17 16:02:38 +0000 | [diff] [blame^] | 219 | jlong token, jint idx) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 220 | { |
Ashok Bhat | 896043d | 2014-01-17 16:02:38 +0000 | [diff] [blame^] | 221 | ResXMLParser* st = reinterpret_cast<ResXMLParser*>(token); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 222 | if (st == NULL) { |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 223 | jniThrowNullPointerException(env, NULL); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 224 | return 0; |
| 225 | } |
| 226 | |
Ashok Bhat | 896043d | 2014-01-17 16:02:38 +0000 | [diff] [blame^] | 227 | return static_cast<jint>(st->getAttributeDataType(idx)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 228 | } |
| 229 | |
| 230 | static jint android_content_XmlBlock_nativeGetAttributeData(JNIEnv* env, jobject clazz, |
Ashok Bhat | 896043d | 2014-01-17 16:02:38 +0000 | [diff] [blame^] | 231 | jlong token, jint idx) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 232 | { |
Ashok Bhat | 896043d | 2014-01-17 16:02:38 +0000 | [diff] [blame^] | 233 | ResXMLParser* st = reinterpret_cast<ResXMLParser*>(token); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 234 | if (st == NULL) { |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 235 | jniThrowNullPointerException(env, NULL); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 236 | return 0; |
| 237 | } |
| 238 | |
Ashok Bhat | 896043d | 2014-01-17 16:02:38 +0000 | [diff] [blame^] | 239 | return static_cast<jint>(st->getAttributeData(idx)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 240 | } |
| 241 | |
| 242 | static jint android_content_XmlBlock_nativeGetAttributeStringValue(JNIEnv* env, jobject clazz, |
Ashok Bhat | 896043d | 2014-01-17 16:02:38 +0000 | [diff] [blame^] | 243 | jlong token, jint idx) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 244 | { |
Ashok Bhat | 896043d | 2014-01-17 16:02:38 +0000 | [diff] [blame^] | 245 | ResXMLParser* st = reinterpret_cast<ResXMLParser*>(token); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 246 | if (st == NULL) { |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 247 | jniThrowNullPointerException(env, NULL); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 248 | return 0; |
| 249 | } |
| 250 | |
Ashok Bhat | 896043d | 2014-01-17 16:02:38 +0000 | [diff] [blame^] | 251 | return static_cast<jint>(st->getAttributeValueStringID(idx)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 252 | } |
| 253 | |
| 254 | static jint android_content_XmlBlock_nativeGetAttributeIndex(JNIEnv* env, jobject clazz, |
Ashok Bhat | 896043d | 2014-01-17 16:02:38 +0000 | [diff] [blame^] | 255 | jlong token, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 256 | jstring ns, jstring name) |
| 257 | { |
Ashok Bhat | 896043d | 2014-01-17 16:02:38 +0000 | [diff] [blame^] | 258 | ResXMLParser* st = reinterpret_cast<ResXMLParser*>(token); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 259 | if (st == NULL || name == NULL) { |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 260 | jniThrowNullPointerException(env, NULL); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 261 | return 0; |
| 262 | } |
| 263 | |
| 264 | const char16_t* ns16 = NULL; |
| 265 | jsize nsLen = 0; |
| 266 | if (ns) { |
| 267 | ns16 = env->GetStringChars(ns, NULL); |
| 268 | nsLen = env->GetStringLength(ns); |
| 269 | } |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 270 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 271 | const char16_t* name16 = env->GetStringChars(name, NULL); |
| 272 | jsize nameLen = env->GetStringLength(name); |
| 273 | |
Ashok Bhat | 896043d | 2014-01-17 16:02:38 +0000 | [diff] [blame^] | 274 | jint idx = static_cast<jint>(st->indexOfAttribute(ns16, nsLen, name16, nameLen)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 275 | |
| 276 | if (ns) { |
| 277 | env->ReleaseStringChars(ns, ns16); |
| 278 | } |
| 279 | env->ReleaseStringChars(name, name16); |
| 280 | |
| 281 | return idx; |
| 282 | } |
| 283 | |
| 284 | static jint android_content_XmlBlock_nativeGetIdAttribute(JNIEnv* env, jobject clazz, |
Ashok Bhat | 896043d | 2014-01-17 16:02:38 +0000 | [diff] [blame^] | 285 | jlong token) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 286 | { |
Ashok Bhat | 896043d | 2014-01-17 16:02:38 +0000 | [diff] [blame^] | 287 | ResXMLParser* st = reinterpret_cast<ResXMLParser*>(token); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 288 | if (st == NULL) { |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 289 | jniThrowNullPointerException(env, NULL); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 290 | return 0; |
| 291 | } |
| 292 | |
| 293 | ssize_t idx = st->indexOfID(); |
Ashok Bhat | 896043d | 2014-01-17 16:02:38 +0000 | [diff] [blame^] | 294 | return idx >= 0 ? static_cast<jint>(st->getAttributeValueStringID(idx)) : -1; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 295 | } |
| 296 | |
| 297 | static jint android_content_XmlBlock_nativeGetClassAttribute(JNIEnv* env, jobject clazz, |
Ashok Bhat | 896043d | 2014-01-17 16:02:38 +0000 | [diff] [blame^] | 298 | jlong token) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 299 | { |
Ashok Bhat | 896043d | 2014-01-17 16:02:38 +0000 | [diff] [blame^] | 300 | ResXMLParser* st = reinterpret_cast<ResXMLParser*>(token); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 301 | if (st == NULL) { |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 302 | jniThrowNullPointerException(env, NULL); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 303 | return 0; |
| 304 | } |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 305 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 306 | ssize_t idx = st->indexOfClass(); |
Ashok Bhat | 896043d | 2014-01-17 16:02:38 +0000 | [diff] [blame^] | 307 | return idx >= 0 ? static_cast<jint>(st->getAttributeValueStringID(idx)) : -1; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 308 | } |
| 309 | |
| 310 | static jint android_content_XmlBlock_nativeGetStyleAttribute(JNIEnv* env, jobject clazz, |
Ashok Bhat | 896043d | 2014-01-17 16:02:38 +0000 | [diff] [blame^] | 311 | jlong token) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 312 | { |
Ashok Bhat | 896043d | 2014-01-17 16:02:38 +0000 | [diff] [blame^] | 313 | ResXMLParser* st = reinterpret_cast<ResXMLParser*>(token); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 314 | if (st == NULL) { |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 315 | jniThrowNullPointerException(env, NULL); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 316 | return 0; |
| 317 | } |
| 318 | |
| 319 | ssize_t idx = st->indexOfStyle(); |
| 320 | if (idx < 0) { |
| 321 | return 0; |
| 322 | } |
| 323 | |
| 324 | Res_value value; |
| 325 | if (st->getAttributeValue(idx, &value) < 0) { |
| 326 | return 0; |
| 327 | } |
| 328 | |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 329 | return value.dataType == value.TYPE_REFERENCE |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 330 | || value.dataType == value.TYPE_ATTRIBUTE |
| 331 | ? value.data : 0; |
| 332 | } |
| 333 | |
| 334 | static void android_content_XmlBlock_nativeDestroyParseState(JNIEnv* env, jobject clazz, |
Ashok Bhat | 896043d | 2014-01-17 16:02:38 +0000 | [diff] [blame^] | 335 | jlong token) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 336 | { |
Ashok Bhat | 896043d | 2014-01-17 16:02:38 +0000 | [diff] [blame^] | 337 | ResXMLParser* st = reinterpret_cast<ResXMLParser*>(token); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 338 | if (st == NULL) { |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 339 | jniThrowNullPointerException(env, NULL); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 340 | return; |
| 341 | } |
| 342 | |
| 343 | delete st; |
| 344 | } |
| 345 | |
| 346 | static void android_content_XmlBlock_nativeDestroy(JNIEnv* env, jobject clazz, |
Ashok Bhat | 896043d | 2014-01-17 16:02:38 +0000 | [diff] [blame^] | 347 | jlong token) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 348 | { |
Ashok Bhat | 896043d | 2014-01-17 16:02:38 +0000 | [diff] [blame^] | 349 | ResXMLTree* osb = reinterpret_cast<ResXMLTree*>(token); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 350 | if (osb == NULL) { |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 351 | jniThrowNullPointerException(env, NULL); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 352 | return; |
| 353 | } |
| 354 | |
| 355 | delete osb; |
| 356 | } |
| 357 | |
| 358 | // ---------------------------------------------------------------------------- |
| 359 | |
| 360 | /* |
| 361 | * JNI registration. |
| 362 | */ |
| 363 | static JNINativeMethod gXmlBlockMethods[] = { |
| 364 | /* name, signature, funcPtr */ |
Ashok Bhat | 896043d | 2014-01-17 16:02:38 +0000 | [diff] [blame^] | 365 | { "nativeCreate", "([BII)J", |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 366 | (void*) android_content_XmlBlock_nativeCreate }, |
Ashok Bhat | 896043d | 2014-01-17 16:02:38 +0000 | [diff] [blame^] | 367 | { "nativeGetStringBlock", "(J)J", |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 368 | (void*) android_content_XmlBlock_nativeGetStringBlock }, |
Ashok Bhat | 896043d | 2014-01-17 16:02:38 +0000 | [diff] [blame^] | 369 | { "nativeCreateParseState", "(J)J", |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 370 | (void*) android_content_XmlBlock_nativeCreateParseState }, |
Ashok Bhat | 896043d | 2014-01-17 16:02:38 +0000 | [diff] [blame^] | 371 | { "nativeNext", "(J)I", |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 372 | (void*) android_content_XmlBlock_nativeNext }, |
Ashok Bhat | 896043d | 2014-01-17 16:02:38 +0000 | [diff] [blame^] | 373 | { "nativeGetNamespace", "(J)I", |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 374 | (void*) android_content_XmlBlock_nativeGetNamespace }, |
Ashok Bhat | 896043d | 2014-01-17 16:02:38 +0000 | [diff] [blame^] | 375 | { "nativeGetName", "(J)I", |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 376 | (void*) android_content_XmlBlock_nativeGetName }, |
Ashok Bhat | 896043d | 2014-01-17 16:02:38 +0000 | [diff] [blame^] | 377 | { "nativeGetText", "(J)I", |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 378 | (void*) android_content_XmlBlock_nativeGetText }, |
Ashok Bhat | 896043d | 2014-01-17 16:02:38 +0000 | [diff] [blame^] | 379 | { "nativeGetLineNumber", "(J)I", |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 380 | (void*) android_content_XmlBlock_nativeGetLineNumber }, |
Ashok Bhat | 896043d | 2014-01-17 16:02:38 +0000 | [diff] [blame^] | 381 | { "nativeGetAttributeCount", "(J)I", |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 382 | (void*) android_content_XmlBlock_nativeGetAttributeCount }, |
Ashok Bhat | 896043d | 2014-01-17 16:02:38 +0000 | [diff] [blame^] | 383 | { "nativeGetAttributeNamespace","(JI)I", |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 384 | (void*) android_content_XmlBlock_nativeGetAttributeNamespace }, |
Ashok Bhat | 896043d | 2014-01-17 16:02:38 +0000 | [diff] [blame^] | 385 | { "nativeGetAttributeName", "(JI)I", |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 386 | (void*) android_content_XmlBlock_nativeGetAttributeName }, |
Ashok Bhat | 896043d | 2014-01-17 16:02:38 +0000 | [diff] [blame^] | 387 | { "nativeGetAttributeResource", "(JI)I", |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 388 | (void*) android_content_XmlBlock_nativeGetAttributeResource }, |
Ashok Bhat | 896043d | 2014-01-17 16:02:38 +0000 | [diff] [blame^] | 389 | { "nativeGetAttributeDataType", "(JI)I", |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 390 | (void*) android_content_XmlBlock_nativeGetAttributeDataType }, |
Ashok Bhat | 896043d | 2014-01-17 16:02:38 +0000 | [diff] [blame^] | 391 | { "nativeGetAttributeData", "(JI)I", |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 392 | (void*) android_content_XmlBlock_nativeGetAttributeData }, |
Ashok Bhat | 896043d | 2014-01-17 16:02:38 +0000 | [diff] [blame^] | 393 | { "nativeGetAttributeStringValue", "(JI)I", |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 394 | (void*) android_content_XmlBlock_nativeGetAttributeStringValue }, |
Ashok Bhat | 896043d | 2014-01-17 16:02:38 +0000 | [diff] [blame^] | 395 | { "nativeGetAttributeIndex", "(JLjava/lang/String;Ljava/lang/String;)I", |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 396 | (void*) android_content_XmlBlock_nativeGetAttributeIndex }, |
Ashok Bhat | 896043d | 2014-01-17 16:02:38 +0000 | [diff] [blame^] | 397 | { "nativeGetIdAttribute", "(J)I", |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 398 | (void*) android_content_XmlBlock_nativeGetIdAttribute }, |
Ashok Bhat | 896043d | 2014-01-17 16:02:38 +0000 | [diff] [blame^] | 399 | { "nativeGetClassAttribute", "(J)I", |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 400 | (void*) android_content_XmlBlock_nativeGetClassAttribute }, |
Ashok Bhat | 896043d | 2014-01-17 16:02:38 +0000 | [diff] [blame^] | 401 | { "nativeGetStyleAttribute", "(J)I", |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 402 | (void*) android_content_XmlBlock_nativeGetStyleAttribute }, |
Ashok Bhat | 896043d | 2014-01-17 16:02:38 +0000 | [diff] [blame^] | 403 | { "nativeDestroyParseState", "(J)V", |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 404 | (void*) android_content_XmlBlock_nativeDestroyParseState }, |
Ashok Bhat | 896043d | 2014-01-17 16:02:38 +0000 | [diff] [blame^] | 405 | { "nativeDestroy", "(J)V", |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 406 | (void*) android_content_XmlBlock_nativeDestroy }, |
| 407 | }; |
| 408 | |
| 409 | int register_android_content_XmlBlock(JNIEnv* env) |
| 410 | { |
| 411 | return AndroidRuntime::registerNativeMethods(env, |
| 412 | "android/content/res/XmlBlock", gXmlBlockMethods, NELEM(gXmlBlockMethods)); |
| 413 | } |
| 414 | |
| 415 | }; // namespace android |