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