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" |
Andreas Gampe | ed6b9df | 2014-11-20 22:02:20 -0800 | [diff] [blame] | 22 | #include <core_jni_helpers.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); |
Adam Lesinski | de898ff | 2014-01-29 18:20:45 -0800 | [diff] [blame] | 50 | ResXMLTree* osb = new ResXMLTree(); |
| 51 | osb->setTo(b+off, len, true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 52 | env->ReleaseByteArrayElements(bArray, b, 0); |
| 53 | |
Adam Lesinski | de898ff | 2014-01-29 18:20:45 -0800 | [diff] [blame] | 54 | if (osb->getError() != NO_ERROR) { |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 55 | jniThrowException(env, "java/lang/IllegalArgumentException", NULL); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 56 | return 0; |
| 57 | } |
| 58 | |
Ashok Bhat | 896043d | 2014-01-17 16:02:38 +0000 | [diff] [blame] | 59 | return reinterpret_cast<jlong>(osb); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 60 | } |
| 61 | |
Ashok Bhat | 896043d | 2014-01-17 16:02:38 +0000 | [diff] [blame] | 62 | static jlong android_content_XmlBlock_nativeGetStringBlock(JNIEnv* env, jobject clazz, |
| 63 | jlong token) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 64 | { |
Ashok Bhat | 896043d | 2014-01-17 16:02:38 +0000 | [diff] [blame] | 65 | ResXMLTree* osb = reinterpret_cast<ResXMLTree*>(token); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 66 | if (osb == NULL) { |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 67 | jniThrowNullPointerException(env, NULL); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 68 | return 0; |
| 69 | } |
| 70 | |
Ashok Bhat | 896043d | 2014-01-17 16:02:38 +0000 | [diff] [blame] | 71 | return reinterpret_cast<jlong>(&osb->getStrings()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 72 | } |
| 73 | |
Ashok Bhat | 896043d | 2014-01-17 16:02:38 +0000 | [diff] [blame] | 74 | static jlong android_content_XmlBlock_nativeCreateParseState(JNIEnv* env, jobject clazz, |
| 75 | jlong token) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 76 | { |
Ashok Bhat | 896043d | 2014-01-17 16:02:38 +0000 | [diff] [blame] | 77 | ResXMLTree* osb = reinterpret_cast<ResXMLTree*>(token); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 78 | if (osb == NULL) { |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 79 | jniThrowNullPointerException(env, NULL); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 80 | return 0; |
| 81 | } |
| 82 | |
| 83 | ResXMLParser* st = new ResXMLParser(*osb); |
| 84 | if (st == NULL) { |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 85 | jniThrowException(env, "java/lang/OutOfMemoryError", NULL); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 86 | return 0; |
| 87 | } |
| 88 | |
| 89 | st->restart(); |
| 90 | |
Ashok Bhat | 896043d | 2014-01-17 16:02:38 +0000 | [diff] [blame] | 91 | return reinterpret_cast<jlong>(st); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 92 | } |
| 93 | |
| 94 | static jint android_content_XmlBlock_nativeNext(JNIEnv* env, jobject clazz, |
Ashok Bhat | 896043d | 2014-01-17 16:02:38 +0000 | [diff] [blame] | 95 | jlong token) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 96 | { |
Ashok Bhat | 896043d | 2014-01-17 16:02:38 +0000 | [diff] [blame] | 97 | ResXMLParser* st = reinterpret_cast<ResXMLParser*>(token); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 98 | if (st == NULL) { |
| 99 | return ResXMLParser::END_DOCUMENT; |
| 100 | } |
| 101 | |
| 102 | do { |
Ashok Bhat | 896043d | 2014-01-17 16:02:38 +0000 | [diff] [blame] | 103 | ResXMLParser::event_code_t code = st->next(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 104 | switch (code) { |
| 105 | case ResXMLParser::START_TAG: |
| 106 | return 2; |
| 107 | case ResXMLParser::END_TAG: |
| 108 | return 3; |
| 109 | case ResXMLParser::TEXT: |
| 110 | return 4; |
| 111 | case ResXMLParser::START_DOCUMENT: |
| 112 | return 0; |
| 113 | case ResXMLParser::END_DOCUMENT: |
| 114 | return 1; |
| 115 | case ResXMLParser::BAD_DOCUMENT: |
| 116 | goto bad; |
Adam Lesinski | de898ff | 2014-01-29 18:20:45 -0800 | [diff] [blame] | 117 | default: |
| 118 | break; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 119 | } |
| 120 | } while (true); |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 121 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 122 | bad: |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 123 | jniThrowException(env, "org/xmlpull/v1/XmlPullParserException", |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 124 | "Corrupt XML binary file"); |
| 125 | return ResXMLParser::BAD_DOCUMENT; |
| 126 | } |
| 127 | |
| 128 | static jint android_content_XmlBlock_nativeGetNamespace(JNIEnv* env, jobject clazz, |
Ashok Bhat | 896043d | 2014-01-17 16:02:38 +0000 | [diff] [blame] | 129 | jlong token) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 130 | { |
Ashok Bhat | 896043d | 2014-01-17 16:02:38 +0000 | [diff] [blame] | 131 | ResXMLParser* st = reinterpret_cast<ResXMLParser*>(token); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 132 | if (st == NULL) { |
| 133 | return -1; |
| 134 | } |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 135 | |
Ashok Bhat | 896043d | 2014-01-17 16:02:38 +0000 | [diff] [blame] | 136 | return static_cast<jint>(st->getElementNamespaceID()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 137 | } |
| 138 | |
| 139 | static jint android_content_XmlBlock_nativeGetName(JNIEnv* env, jobject clazz, |
Ashok Bhat | 896043d | 2014-01-17 16:02:38 +0000 | [diff] [blame] | 140 | jlong token) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 141 | { |
Ashok Bhat | 896043d | 2014-01-17 16:02:38 +0000 | [diff] [blame] | 142 | ResXMLParser* st = reinterpret_cast<ResXMLParser*>(token); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 143 | if (st == NULL) { |
| 144 | return -1; |
| 145 | } |
| 146 | |
Ashok Bhat | 896043d | 2014-01-17 16:02:38 +0000 | [diff] [blame] | 147 | return static_cast<jint>(st->getElementNameID()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 148 | } |
| 149 | |
| 150 | static jint android_content_XmlBlock_nativeGetText(JNIEnv* env, jobject clazz, |
Ashok Bhat | 896043d | 2014-01-17 16:02:38 +0000 | [diff] [blame] | 151 | jlong token) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 152 | { |
Ashok Bhat | 896043d | 2014-01-17 16:02:38 +0000 | [diff] [blame] | 153 | ResXMLParser* st = reinterpret_cast<ResXMLParser*>(token); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 154 | if (st == NULL) { |
| 155 | return -1; |
| 156 | } |
| 157 | |
Ashok Bhat | 896043d | 2014-01-17 16:02:38 +0000 | [diff] [blame] | 158 | return static_cast<jint>(st->getTextID()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 159 | } |
| 160 | |
| 161 | static jint android_content_XmlBlock_nativeGetLineNumber(JNIEnv* env, jobject clazz, |
Ashok Bhat | 896043d | 2014-01-17 16:02:38 +0000 | [diff] [blame] | 162 | jlong token) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 163 | { |
Ashok Bhat | 896043d | 2014-01-17 16:02:38 +0000 | [diff] [blame] | 164 | ResXMLParser* st = reinterpret_cast<ResXMLParser*>(token); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 165 | if (st == NULL) { |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 166 | jniThrowNullPointerException(env, NULL); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 167 | return 0; |
| 168 | } |
| 169 | |
Ashok Bhat | 896043d | 2014-01-17 16:02:38 +0000 | [diff] [blame] | 170 | return static_cast<jint>(st->getLineNumber()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 171 | } |
| 172 | |
| 173 | static jint android_content_XmlBlock_nativeGetAttributeCount(JNIEnv* env, jobject clazz, |
Ashok Bhat | 896043d | 2014-01-17 16:02:38 +0000 | [diff] [blame] | 174 | jlong token) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 175 | { |
Ashok Bhat | 896043d | 2014-01-17 16:02:38 +0000 | [diff] [blame] | 176 | ResXMLParser* st = reinterpret_cast<ResXMLParser*>(token); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 177 | if (st == NULL) { |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 178 | jniThrowNullPointerException(env, NULL); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 179 | return 0; |
| 180 | } |
| 181 | |
Ashok Bhat | 896043d | 2014-01-17 16:02:38 +0000 | [diff] [blame] | 182 | return static_cast<jint>(st->getAttributeCount()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 183 | } |
| 184 | |
| 185 | static jint android_content_XmlBlock_nativeGetAttributeNamespace(JNIEnv* env, jobject clazz, |
Ashok Bhat | 896043d | 2014-01-17 16:02:38 +0000 | [diff] [blame] | 186 | jlong token, jint idx) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 187 | { |
Ashok Bhat | 896043d | 2014-01-17 16:02:38 +0000 | [diff] [blame] | 188 | ResXMLParser* st = reinterpret_cast<ResXMLParser*>(token); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 189 | if (st == NULL) { |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 190 | jniThrowNullPointerException(env, NULL); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 191 | return 0; |
| 192 | } |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 193 | |
Ashok Bhat | 896043d | 2014-01-17 16:02:38 +0000 | [diff] [blame] | 194 | return static_cast<jint>(st->getAttributeNamespaceID(idx)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 195 | } |
| 196 | |
| 197 | static jint android_content_XmlBlock_nativeGetAttributeName(JNIEnv* env, jobject clazz, |
Ashok Bhat | 896043d | 2014-01-17 16:02:38 +0000 | [diff] [blame] | 198 | jlong token, jint idx) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 199 | { |
Ashok Bhat | 896043d | 2014-01-17 16:02:38 +0000 | [diff] [blame] | 200 | ResXMLParser* st = reinterpret_cast<ResXMLParser*>(token); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 201 | if (st == NULL) { |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 202 | jniThrowNullPointerException(env, NULL); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 203 | return 0; |
| 204 | } |
| 205 | |
Ashok Bhat | 896043d | 2014-01-17 16:02:38 +0000 | [diff] [blame] | 206 | return static_cast<jint>(st->getAttributeNameID(idx)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 207 | } |
| 208 | |
| 209 | static jint android_content_XmlBlock_nativeGetAttributeResource(JNIEnv* env, jobject clazz, |
Ashok Bhat | 896043d | 2014-01-17 16:02:38 +0000 | [diff] [blame] | 210 | jlong token, jint idx) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 211 | { |
Ashok Bhat | 896043d | 2014-01-17 16:02:38 +0000 | [diff] [blame] | 212 | ResXMLParser* st = reinterpret_cast<ResXMLParser*>(token); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 213 | if (st == NULL) { |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 214 | jniThrowNullPointerException(env, NULL); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 215 | return 0; |
| 216 | } |
| 217 | |
Ashok Bhat | 896043d | 2014-01-17 16:02:38 +0000 | [diff] [blame] | 218 | return static_cast<jint>(st->getAttributeNameResID(idx)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 219 | } |
| 220 | |
| 221 | static jint android_content_XmlBlock_nativeGetAttributeDataType(JNIEnv* env, jobject clazz, |
Ashok Bhat | 896043d | 2014-01-17 16:02:38 +0000 | [diff] [blame] | 222 | jlong token, jint idx) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 223 | { |
Ashok Bhat | 896043d | 2014-01-17 16:02:38 +0000 | [diff] [blame] | 224 | ResXMLParser* st = reinterpret_cast<ResXMLParser*>(token); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 225 | if (st == NULL) { |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 226 | jniThrowNullPointerException(env, NULL); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 227 | return 0; |
| 228 | } |
| 229 | |
Ashok Bhat | 896043d | 2014-01-17 16:02:38 +0000 | [diff] [blame] | 230 | return static_cast<jint>(st->getAttributeDataType(idx)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 231 | } |
| 232 | |
| 233 | static jint android_content_XmlBlock_nativeGetAttributeData(JNIEnv* env, jobject clazz, |
Ashok Bhat | 896043d | 2014-01-17 16:02:38 +0000 | [diff] [blame] | 234 | jlong token, jint idx) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 235 | { |
Ashok Bhat | 896043d | 2014-01-17 16:02:38 +0000 | [diff] [blame] | 236 | ResXMLParser* st = reinterpret_cast<ResXMLParser*>(token); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 237 | if (st == NULL) { |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 238 | jniThrowNullPointerException(env, NULL); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 239 | return 0; |
| 240 | } |
| 241 | |
Ashok Bhat | 896043d | 2014-01-17 16:02:38 +0000 | [diff] [blame] | 242 | return static_cast<jint>(st->getAttributeData(idx)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 243 | } |
| 244 | |
| 245 | static jint android_content_XmlBlock_nativeGetAttributeStringValue(JNIEnv* env, jobject clazz, |
Ashok Bhat | 896043d | 2014-01-17 16:02:38 +0000 | [diff] [blame] | 246 | jlong token, jint idx) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 247 | { |
Ashok Bhat | 896043d | 2014-01-17 16:02:38 +0000 | [diff] [blame] | 248 | ResXMLParser* st = reinterpret_cast<ResXMLParser*>(token); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 249 | if (st == NULL) { |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 250 | jniThrowNullPointerException(env, NULL); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 251 | return 0; |
| 252 | } |
| 253 | |
Ashok Bhat | 896043d | 2014-01-17 16:02:38 +0000 | [diff] [blame] | 254 | return static_cast<jint>(st->getAttributeValueStringID(idx)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 255 | } |
| 256 | |
| 257 | static jint android_content_XmlBlock_nativeGetAttributeIndex(JNIEnv* env, jobject clazz, |
Ashok Bhat | 896043d | 2014-01-17 16:02:38 +0000 | [diff] [blame] | 258 | jlong token, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 259 | jstring ns, jstring name) |
| 260 | { |
Ashok Bhat | 896043d | 2014-01-17 16:02:38 +0000 | [diff] [blame] | 261 | ResXMLParser* st = reinterpret_cast<ResXMLParser*>(token); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 262 | if (st == NULL || name == NULL) { |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 263 | jniThrowNullPointerException(env, NULL); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 264 | return 0; |
| 265 | } |
| 266 | |
| 267 | const char16_t* ns16 = NULL; |
| 268 | jsize nsLen = 0; |
| 269 | if (ns) { |
Dan Albert | 6698749 | 2014-11-20 11:41:21 -0800 | [diff] [blame] | 270 | ns16 = reinterpret_cast<const char16_t*>(env->GetStringChars(ns, NULL)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 271 | nsLen = env->GetStringLength(ns); |
| 272 | } |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 273 | |
Dan Albert | 6698749 | 2014-11-20 11:41:21 -0800 | [diff] [blame] | 274 | const char16_t* name16 = reinterpret_cast<const char16_t*>( |
| 275 | env->GetStringChars(name, NULL)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 276 | jsize nameLen = env->GetStringLength(name); |
| 277 | |
Ashok Bhat | 896043d | 2014-01-17 16:02:38 +0000 | [diff] [blame] | 278 | 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] | 279 | |
| 280 | if (ns) { |
Dan Albert | 6698749 | 2014-11-20 11:41:21 -0800 | [diff] [blame] | 281 | env->ReleaseStringChars(ns, reinterpret_cast<const jchar*>(ns16)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 282 | } |
Dan Albert | 6698749 | 2014-11-20 11:41:21 -0800 | [diff] [blame] | 283 | env->ReleaseStringChars(name, reinterpret_cast<const jchar*>(name16)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 284 | |
| 285 | return idx; |
| 286 | } |
| 287 | |
| 288 | static jint android_content_XmlBlock_nativeGetIdAttribute(JNIEnv* env, jobject clazz, |
Ashok Bhat | 896043d | 2014-01-17 16:02:38 +0000 | [diff] [blame] | 289 | jlong token) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 290 | { |
Ashok Bhat | 896043d | 2014-01-17 16:02:38 +0000 | [diff] [blame] | 291 | ResXMLParser* st = reinterpret_cast<ResXMLParser*>(token); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 292 | if (st == NULL) { |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 293 | jniThrowNullPointerException(env, NULL); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 294 | return 0; |
| 295 | } |
| 296 | |
| 297 | ssize_t idx = st->indexOfID(); |
Ashok Bhat | 896043d | 2014-01-17 16:02:38 +0000 | [diff] [blame] | 298 | 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] | 299 | } |
| 300 | |
| 301 | static jint android_content_XmlBlock_nativeGetClassAttribute(JNIEnv* env, jobject clazz, |
Ashok Bhat | 896043d | 2014-01-17 16:02:38 +0000 | [diff] [blame] | 302 | jlong token) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 303 | { |
Ashok Bhat | 896043d | 2014-01-17 16:02:38 +0000 | [diff] [blame] | 304 | ResXMLParser* st = reinterpret_cast<ResXMLParser*>(token); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 305 | if (st == NULL) { |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 306 | jniThrowNullPointerException(env, NULL); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 307 | return 0; |
| 308 | } |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 309 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 310 | ssize_t idx = st->indexOfClass(); |
Ashok Bhat | 896043d | 2014-01-17 16:02:38 +0000 | [diff] [blame] | 311 | 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] | 312 | } |
| 313 | |
| 314 | static jint android_content_XmlBlock_nativeGetStyleAttribute(JNIEnv* env, jobject clazz, |
Ashok Bhat | 896043d | 2014-01-17 16:02:38 +0000 | [diff] [blame] | 315 | jlong token) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 316 | { |
Ashok Bhat | 896043d | 2014-01-17 16:02:38 +0000 | [diff] [blame] | 317 | ResXMLParser* st = reinterpret_cast<ResXMLParser*>(token); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 318 | if (st == NULL) { |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 319 | jniThrowNullPointerException(env, NULL); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 320 | return 0; |
| 321 | } |
| 322 | |
| 323 | ssize_t idx = st->indexOfStyle(); |
| 324 | if (idx < 0) { |
| 325 | return 0; |
| 326 | } |
| 327 | |
| 328 | Res_value value; |
| 329 | if (st->getAttributeValue(idx, &value) < 0) { |
| 330 | return 0; |
| 331 | } |
| 332 | |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 333 | return value.dataType == value.TYPE_REFERENCE |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 334 | || value.dataType == value.TYPE_ATTRIBUTE |
| 335 | ? value.data : 0; |
| 336 | } |
| 337 | |
| 338 | static void android_content_XmlBlock_nativeDestroyParseState(JNIEnv* env, jobject clazz, |
Ashok Bhat | 896043d | 2014-01-17 16:02:38 +0000 | [diff] [blame] | 339 | jlong token) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 340 | { |
Ashok Bhat | 896043d | 2014-01-17 16:02:38 +0000 | [diff] [blame] | 341 | ResXMLParser* st = reinterpret_cast<ResXMLParser*>(token); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 342 | if (st == NULL) { |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 343 | jniThrowNullPointerException(env, NULL); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 344 | return; |
| 345 | } |
| 346 | |
| 347 | delete st; |
| 348 | } |
| 349 | |
| 350 | static void android_content_XmlBlock_nativeDestroy(JNIEnv* env, jobject clazz, |
Ashok Bhat | 896043d | 2014-01-17 16:02:38 +0000 | [diff] [blame] | 351 | jlong token) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 352 | { |
Ashok Bhat | 896043d | 2014-01-17 16:02:38 +0000 | [diff] [blame] | 353 | ResXMLTree* osb = reinterpret_cast<ResXMLTree*>(token); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 354 | if (osb == NULL) { |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 355 | jniThrowNullPointerException(env, NULL); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 356 | return; |
| 357 | } |
| 358 | |
| 359 | delete osb; |
| 360 | } |
| 361 | |
| 362 | // ---------------------------------------------------------------------------- |
| 363 | |
| 364 | /* |
| 365 | * JNI registration. |
| 366 | */ |
Daniel Micay | 76f6a86 | 2015-09-19 17:31:01 -0400 | [diff] [blame] | 367 | static const JNINativeMethod gXmlBlockMethods[] = { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 368 | /* name, signature, funcPtr */ |
Ashok Bhat | 896043d | 2014-01-17 16:02:38 +0000 | [diff] [blame] | 369 | { "nativeCreate", "([BII)J", |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 370 | (void*) android_content_XmlBlock_nativeCreate }, |
Ashok Bhat | 896043d | 2014-01-17 16:02:38 +0000 | [diff] [blame] | 371 | { "nativeGetStringBlock", "(J)J", |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 372 | (void*) android_content_XmlBlock_nativeGetStringBlock }, |
Ashok Bhat | 896043d | 2014-01-17 16:02:38 +0000 | [diff] [blame] | 373 | { "nativeCreateParseState", "(J)J", |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 374 | (void*) android_content_XmlBlock_nativeCreateParseState }, |
Ashok Bhat | 896043d | 2014-01-17 16:02:38 +0000 | [diff] [blame] | 375 | { "nativeDestroyParseState", "(J)V", |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 376 | (void*) android_content_XmlBlock_nativeDestroyParseState }, |
Ashok Bhat | 896043d | 2014-01-17 16:02:38 +0000 | [diff] [blame] | 377 | { "nativeDestroy", "(J)V", |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 378 | (void*) android_content_XmlBlock_nativeDestroy }, |
John Reck | 3299522 | 2016-10-07 11:02:20 -0700 | [diff] [blame] | 379 | |
| 380 | // ------------------- @FastNative ---------------------- |
| 381 | |
| 382 | { "nativeNext", "(J)I", |
| 383 | (void*) android_content_XmlBlock_nativeNext }, |
| 384 | { "nativeGetNamespace", "(J)I", |
| 385 | (void*) android_content_XmlBlock_nativeGetNamespace }, |
| 386 | { "nativeGetName", "(J)I", |
| 387 | (void*) android_content_XmlBlock_nativeGetName }, |
| 388 | { "nativeGetText", "(J)I", |
| 389 | (void*) android_content_XmlBlock_nativeGetText }, |
| 390 | { "nativeGetLineNumber", "(J)I", |
| 391 | (void*) android_content_XmlBlock_nativeGetLineNumber }, |
| 392 | { "nativeGetAttributeCount", "(J)I", |
| 393 | (void*) android_content_XmlBlock_nativeGetAttributeCount }, |
| 394 | { "nativeGetAttributeNamespace","(JI)I", |
| 395 | (void*) android_content_XmlBlock_nativeGetAttributeNamespace }, |
| 396 | { "nativeGetAttributeName", "(JI)I", |
| 397 | (void*) android_content_XmlBlock_nativeGetAttributeName }, |
| 398 | { "nativeGetAttributeResource", "(JI)I", |
| 399 | (void*) android_content_XmlBlock_nativeGetAttributeResource }, |
| 400 | { "nativeGetAttributeDataType", "(JI)I", |
| 401 | (void*) android_content_XmlBlock_nativeGetAttributeDataType }, |
| 402 | { "nativeGetAttributeData", "(JI)I", |
| 403 | (void*) android_content_XmlBlock_nativeGetAttributeData }, |
| 404 | { "nativeGetAttributeStringValue", "(JI)I", |
| 405 | (void*) android_content_XmlBlock_nativeGetAttributeStringValue }, |
| 406 | { "nativeGetAttributeIndex", "(JLjava/lang/String;Ljava/lang/String;)I", |
| 407 | (void*) android_content_XmlBlock_nativeGetAttributeIndex }, |
| 408 | { "nativeGetIdAttribute", "(J)I", |
| 409 | (void*) android_content_XmlBlock_nativeGetIdAttribute }, |
| 410 | { "nativeGetClassAttribute", "(J)I", |
| 411 | (void*) android_content_XmlBlock_nativeGetClassAttribute }, |
| 412 | { "nativeGetStyleAttribute", "(J)I", |
| 413 | (void*) android_content_XmlBlock_nativeGetStyleAttribute }, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 414 | }; |
| 415 | |
| 416 | int register_android_content_XmlBlock(JNIEnv* env) |
| 417 | { |
Andreas Gampe | ed6b9df | 2014-11-20 22:02:20 -0800 | [diff] [blame] | 418 | return RegisterMethodsOrDie(env, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 419 | "android/content/res/XmlBlock", gXmlBlockMethods, NELEM(gXmlBlockMethods)); |
| 420 | } |
| 421 | |
| 422 | }; // namespace android |