1ad2d07d2d98a46babb2a9472413fe9ce5080ca76Adam Lesinski/* 2ad2d07d2d98a46babb2a9472413fe9ce5080ca76Adam Lesinski * Copyright (C) 2014 The Android Open Source Project 3ad2d07d2d98a46babb2a9472413fe9ce5080ca76Adam Lesinski * 4ad2d07d2d98a46babb2a9472413fe9ce5080ca76Adam Lesinski * Licensed under the Apache License, Version 2.0 (the "License"); 5ad2d07d2d98a46babb2a9472413fe9ce5080ca76Adam Lesinski * you may not use this file except in compliance with the License. 6ad2d07d2d98a46babb2a9472413fe9ce5080ca76Adam Lesinski * You may obtain a copy of the License at 7ad2d07d2d98a46babb2a9472413fe9ce5080ca76Adam Lesinski * 8ad2d07d2d98a46babb2a9472413fe9ce5080ca76Adam Lesinski * http://www.apache.org/licenses/LICENSE-2.0 9ad2d07d2d98a46babb2a9472413fe9ce5080ca76Adam Lesinski * 10ad2d07d2d98a46babb2a9472413fe9ce5080ca76Adam Lesinski * Unless required by applicable law or agreed to in writing, software 11ad2d07d2d98a46babb2a9472413fe9ce5080ca76Adam Lesinski * distributed under the License is distributed on an "AS IS" BASIS, 12ad2d07d2d98a46babb2a9472413fe9ce5080ca76Adam Lesinski * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13ad2d07d2d98a46babb2a9472413fe9ce5080ca76Adam Lesinski * See the License for the specific language governing permissions and 14ad2d07d2d98a46babb2a9472413fe9ce5080ca76Adam Lesinski * limitations under the License. 15ad2d07d2d98a46babb2a9472413fe9ce5080ca76Adam Lesinski */ 16ad2d07d2d98a46babb2a9472413fe9ce5080ca76Adam Lesinski 17ad2d07d2d98a46babb2a9472413fe9ce5080ca76Adam Lesinski#ifndef __AAPT_XML_H 18ad2d07d2d98a46babb2a9472413fe9ce5080ca76Adam Lesinski#define __AAPT_XML_H 19ad2d07d2d98a46babb2a9472413fe9ce5080ca76Adam Lesinski 20ad2d07d2d98a46babb2a9472413fe9ce5080ca76Adam Lesinski#include <androidfw/ResourceTypes.h> 21ad2d07d2d98a46babb2a9472413fe9ce5080ca76Adam Lesinski#include <utils/String8.h> 22ad2d07d2d98a46babb2a9472413fe9ce5080ca76Adam Lesinski 23ad2d07d2d98a46babb2a9472413fe9ce5080ca76Adam Lesinski/** 24ad2d07d2d98a46babb2a9472413fe9ce5080ca76Adam Lesinski * Utility methods for dealing with ResXMLTree. 25ad2d07d2d98a46babb2a9472413fe9ce5080ca76Adam Lesinski */ 26ad2d07d2d98a46babb2a9472413fe9ce5080ca76Adam Lesinskinamespace AaptXml { 27ad2d07d2d98a46babb2a9472413fe9ce5080ca76Adam Lesinski 28ad2d07d2d98a46babb2a9472413fe9ce5080ca76Adam Lesinski/** 29ad2d07d2d98a46babb2a9472413fe9ce5080ca76Adam Lesinski * Returns the index of the attribute, or < 0 if it was not found. 30ad2d07d2d98a46babb2a9472413fe9ce5080ca76Adam Lesinski */ 31ad2d07d2d98a46babb2a9472413fe9ce5080ca76Adam Lesinskissize_t indexOfAttribute(const android::ResXMLTree& tree, uint32_t attrRes); 32ad2d07d2d98a46babb2a9472413fe9ce5080ca76Adam Lesinski 33ad2d07d2d98a46babb2a9472413fe9ce5080ca76Adam Lesinski/** 34ad2d07d2d98a46babb2a9472413fe9ce5080ca76Adam Lesinski * Returns the string value for the specified attribute. 35ad2d07d2d98a46babb2a9472413fe9ce5080ca76Adam Lesinski * The string must be present in the ResXMLTree's string pool (inline in the XML). 36ad2d07d2d98a46babb2a9472413fe9ce5080ca76Adam Lesinski */ 37ad2d07d2d98a46babb2a9472413fe9ce5080ca76Adam Lesinskiandroid::String8 getAttribute(const android::ResXMLTree& tree, const char* ns, 38ad2d07d2d98a46babb2a9472413fe9ce5080ca76Adam Lesinski const char* attr, android::String8* outError = NULL); 39ad2d07d2d98a46babb2a9472413fe9ce5080ca76Adam Lesinski 40ad2d07d2d98a46babb2a9472413fe9ce5080ca76Adam Lesinski/** 41ad2d07d2d98a46babb2a9472413fe9ce5080ca76Adam Lesinski * Returns the string value for the specified attribute, or an empty string 42ad2d07d2d98a46babb2a9472413fe9ce5080ca76Adam Lesinski * if the attribute does not exist. 43ad2d07d2d98a46babb2a9472413fe9ce5080ca76Adam Lesinski * The string must be present in the ResXMLTree's string pool (inline in the XML). 44ad2d07d2d98a46babb2a9472413fe9ce5080ca76Adam Lesinski */ 45ad2d07d2d98a46babb2a9472413fe9ce5080ca76Adam Lesinskiandroid::String8 getAttribute(const android::ResXMLTree& tree, uint32_t attrRes, 46ad2d07d2d98a46babb2a9472413fe9ce5080ca76Adam Lesinski android::String8* outError = NULL); 47ad2d07d2d98a46babb2a9472413fe9ce5080ca76Adam Lesinski 48ad2d07d2d98a46babb2a9472413fe9ce5080ca76Adam Lesinski/** 49ad2d07d2d98a46babb2a9472413fe9ce5080ca76Adam Lesinski * Returns the integer value for the specified attribute, or the default value 50ad2d07d2d98a46babb2a9472413fe9ce5080ca76Adam Lesinski * if the attribute does not exist. 51ad2d07d2d98a46babb2a9472413fe9ce5080ca76Adam Lesinski * The integer must be declared inline in the XML. 52ad2d07d2d98a46babb2a9472413fe9ce5080ca76Adam Lesinski */ 53ad2d07d2d98a46babb2a9472413fe9ce5080ca76Adam Lesinskiint32_t getIntegerAttribute(const android::ResXMLTree& tree, const char* ns, 54ad2d07d2d98a46babb2a9472413fe9ce5080ca76Adam Lesinski const char* attr, int32_t defValue = -1, android::String8* outError = NULL); 55ad2d07d2d98a46babb2a9472413fe9ce5080ca76Adam Lesinski 56ad2d07d2d98a46babb2a9472413fe9ce5080ca76Adam Lesinski/** 57ad2d07d2d98a46babb2a9472413fe9ce5080ca76Adam Lesinski * Returns the integer value for the specified attribute, or the default value 58ad2d07d2d98a46babb2a9472413fe9ce5080ca76Adam Lesinski * if the attribute does not exist. 59ad2d07d2d98a46babb2a9472413fe9ce5080ca76Adam Lesinski * The integer must be declared inline in the XML. 60ad2d07d2d98a46babb2a9472413fe9ce5080ca76Adam Lesinski */ 61ad2d07d2d98a46babb2a9472413fe9ce5080ca76Adam Lesinskiinline int32_t getIntegerAttribute(const android::ResXMLTree& tree, const char* ns, 62ad2d07d2d98a46babb2a9472413fe9ce5080ca76Adam Lesinski const char* attr, android::String8* outError) { 63ad2d07d2d98a46babb2a9472413fe9ce5080ca76Adam Lesinski return getIntegerAttribute(tree, ns, attr, -1, outError); 64ad2d07d2d98a46babb2a9472413fe9ce5080ca76Adam Lesinski} 65ad2d07d2d98a46babb2a9472413fe9ce5080ca76Adam Lesinski 66ad2d07d2d98a46babb2a9472413fe9ce5080ca76Adam Lesinski/** 67ad2d07d2d98a46babb2a9472413fe9ce5080ca76Adam Lesinski * Returns the integer value for the specified attribute, or the default value 68ad2d07d2d98a46babb2a9472413fe9ce5080ca76Adam Lesinski * if the attribute does not exist. 69ad2d07d2d98a46babb2a9472413fe9ce5080ca76Adam Lesinski * The integer must be declared inline in the XML. 70ad2d07d2d98a46babb2a9472413fe9ce5080ca76Adam Lesinski */ 71ad2d07d2d98a46babb2a9472413fe9ce5080ca76Adam Lesinskiint32_t getIntegerAttribute(const android::ResXMLTree& tree, uint32_t attrRes, 72ad2d07d2d98a46babb2a9472413fe9ce5080ca76Adam Lesinski int32_t defValue = -1, android::String8* outError = NULL); 73ad2d07d2d98a46babb2a9472413fe9ce5080ca76Adam Lesinski 74ad2d07d2d98a46babb2a9472413fe9ce5080ca76Adam Lesinski/** 75ad2d07d2d98a46babb2a9472413fe9ce5080ca76Adam Lesinski * Returns the integer value for the specified attribute, or the default value 76ad2d07d2d98a46babb2a9472413fe9ce5080ca76Adam Lesinski * if the attribute does not exist. 77ad2d07d2d98a46babb2a9472413fe9ce5080ca76Adam Lesinski * The integer must be declared inline in the XML. 78ad2d07d2d98a46babb2a9472413fe9ce5080ca76Adam Lesinski */ 79ad2d07d2d98a46babb2a9472413fe9ce5080ca76Adam Lesinskiinline int32_t getIntegerAttribute(const android::ResXMLTree& tree, uint32_t attrRes, 80ad2d07d2d98a46babb2a9472413fe9ce5080ca76Adam Lesinski android::String8* outError) { 81ad2d07d2d98a46babb2a9472413fe9ce5080ca76Adam Lesinski return getIntegerAttribute(tree, attrRes, -1, outError); 82ad2d07d2d98a46babb2a9472413fe9ce5080ca76Adam Lesinski} 83ad2d07d2d98a46babb2a9472413fe9ce5080ca76Adam Lesinski 84ad2d07d2d98a46babb2a9472413fe9ce5080ca76Adam Lesinski/** 85ad2d07d2d98a46babb2a9472413fe9ce5080ca76Adam Lesinski * Returns the integer value for the specified attribute, or the default value 86ad2d07d2d98a46babb2a9472413fe9ce5080ca76Adam Lesinski * if the attribute does not exist. 87ad2d07d2d98a46babb2a9472413fe9ce5080ca76Adam Lesinski * The integer may be a resource in the supplied ResTable. 88ad2d07d2d98a46babb2a9472413fe9ce5080ca76Adam Lesinski */ 89ad2d07d2d98a46babb2a9472413fe9ce5080ca76Adam Lesinskiint32_t getResolvedIntegerAttribute(const android::ResTable& resTable, 90ad2d07d2d98a46babb2a9472413fe9ce5080ca76Adam Lesinski const android::ResXMLTree& tree, uint32_t attrRes, int32_t defValue = -1, 91ad2d07d2d98a46babb2a9472413fe9ce5080ca76Adam Lesinski android::String8* outError = NULL); 92ad2d07d2d98a46babb2a9472413fe9ce5080ca76Adam Lesinski 93ad2d07d2d98a46babb2a9472413fe9ce5080ca76Adam Lesinski/** 94ad2d07d2d98a46babb2a9472413fe9ce5080ca76Adam Lesinski * Returns the integer value for the specified attribute, or the default value 95ad2d07d2d98a46babb2a9472413fe9ce5080ca76Adam Lesinski * if the attribute does not exist. 96ad2d07d2d98a46babb2a9472413fe9ce5080ca76Adam Lesinski * The integer may be a resource in the supplied ResTable. 97ad2d07d2d98a46babb2a9472413fe9ce5080ca76Adam Lesinski */ 98ad2d07d2d98a46babb2a9472413fe9ce5080ca76Adam Lesinskiinline int32_t getResolvedIntegerAttribute(const android::ResTable& resTable, 99ad2d07d2d98a46babb2a9472413fe9ce5080ca76Adam Lesinski const android::ResXMLTree& tree, uint32_t attrRes, 100ad2d07d2d98a46babb2a9472413fe9ce5080ca76Adam Lesinski android::String8* outError) { 101ad2d07d2d98a46babb2a9472413fe9ce5080ca76Adam Lesinski return getResolvedIntegerAttribute(resTable, tree, attrRes, -1, outError); 102ad2d07d2d98a46babb2a9472413fe9ce5080ca76Adam Lesinski} 103ad2d07d2d98a46babb2a9472413fe9ce5080ca76Adam Lesinski 104ad2d07d2d98a46babb2a9472413fe9ce5080ca76Adam Lesinski/** 105ad2d07d2d98a46babb2a9472413fe9ce5080ca76Adam Lesinski * Returns the string value for the specified attribute, or an empty string 106ad2d07d2d98a46babb2a9472413fe9ce5080ca76Adam Lesinski * if the attribute does not exist. 107ad2d07d2d98a46babb2a9472413fe9ce5080ca76Adam Lesinski * The string may be a resource in the supplied ResTable. 108ad2d07d2d98a46babb2a9472413fe9ce5080ca76Adam Lesinski */ 109ad2d07d2d98a46babb2a9472413fe9ce5080ca76Adam Lesinskiandroid::String8 getResolvedAttribute(const android::ResTable& resTable, 110ad2d07d2d98a46babb2a9472413fe9ce5080ca76Adam Lesinski const android::ResXMLTree& tree, uint32_t attrRes, 111ad2d07d2d98a46babb2a9472413fe9ce5080ca76Adam Lesinski android::String8* outError = NULL); 112ad2d07d2d98a46babb2a9472413fe9ce5080ca76Adam Lesinski 113ad2d07d2d98a46babb2a9472413fe9ce5080ca76Adam Lesinski/** 114ad2d07d2d98a46babb2a9472413fe9ce5080ca76Adam Lesinski * Returns the resource for the specified attribute in the outValue parameter. 115ad2d07d2d98a46babb2a9472413fe9ce5080ca76Adam Lesinski * The resource may be a resource in the supplied ResTable. 116ad2d07d2d98a46babb2a9472413fe9ce5080ca76Adam Lesinski */ 117ad2d07d2d98a46babb2a9472413fe9ce5080ca76Adam Lesinskivoid getResolvedResourceAttribute(const android::ResTable& resTable, 118ad2d07d2d98a46babb2a9472413fe9ce5080ca76Adam Lesinski const android::ResXMLTree& tree, uint32_t attrRes, android::Res_value* outValue, 119ad2d07d2d98a46babb2a9472413fe9ce5080ca76Adam Lesinski android::String8* outError = NULL); 120ad2d07d2d98a46babb2a9472413fe9ce5080ca76Adam Lesinski 121ad2d07d2d98a46babb2a9472413fe9ce5080ca76Adam Lesinski} // namespace AaptXml 122ad2d07d2d98a46babb2a9472413fe9ce5080ca76Adam Lesinski 123ad2d07d2d98a46babb2a9472413fe9ce5080ca76Adam Lesinski#endif // __AAPT_XML_H 124