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