2 // Copyright 2006 The Android Open Source Project
4 // Build resource files from raw assets.
10 #include "StringPool.h"
11 #include "ResourceTable.h"
15 extern const char* const RESOURCES_ROOT_NAMESPACE
;
16 extern const char* const RESOURCES_ANDROID_NAMESPACE
;
18 bool isWhitespace(const char16_t* str
);
20 String16
getNamespaceResourcePackage(String16 namespaceUri
, bool* outIsPublic
= NULL
);
22 status_t
parseStyledString(Bundle
* bundle
,
25 const String16
& endTag
,
27 Vector
<StringPool::entry_style_span
>* outSpans
,
28 bool isPseudolocalizable
);
30 void printXMLBlock(ResXMLTree
* block
);
32 status_t
parseXMLResource(const sp
<AaptFile
>& file
, ResXMLTree
* outTree
,
33 bool stripAll
=true, bool keepComments
=false,
34 const char** cDataTags
=NULL
);
36 class XMLNode
: public RefBase
39 static sp
<XMLNode
> parse(const sp
<AaptFile
>& file
);
42 sp
<XMLNode
> newNamespace(const String8
& filename
, const String16
& prefix
, const String16
& uri
) {
43 return new XMLNode(filename
, prefix
, uri
, true);
47 sp
<XMLNode
> newElement(const String8
& filename
, const String16
& ns
, const String16
& name
) {
48 return new XMLNode(filename
, ns
, name
, false);
52 sp
<XMLNode
> newCData(const String8
& filename
) {
53 return new XMLNode(filename
);
64 const String16
& getNamespacePrefix() const;
65 const String16
& getNamespaceUri() const;
67 const String16
& getElementNamespace() const;
68 const String16
& getElementName() const;
69 const Vector
<sp
<XMLNode
> >& getChildren() const;
71 struct attribute_entry
{
72 attribute_entry() : index(~(uint32_t)0), nameResId(0)
74 value
.dataType
= Res_value::TYPE_NULL
;
77 bool needStringValue() const {
79 || value
.dataType
== Res_value::TYPE_NULL
80 || value
.dataType
== Res_value::TYPE_STRING
;
89 mutable uint32_t namePoolIdx
;
92 const Vector
<attribute_entry
>& getAttributes() const;
94 const String16
& getCData() const;
96 const String16
& getComment() const;
98 int32_t getStartLineNumber() const;
99 int32_t getEndLineNumber() const;
101 status_t
addChild(const sp
<XMLNode
>& child
);
103 status_t
addAttribute(const String16
& ns
, const String16
& name
,
104 const String16
& value
);
106 void setAttributeResID(size_t attrIdx
, uint32_t resId
);
108 status_t
appendChars(const String16
& chars
);
110 status_t
appendComment(const String16
& comment
);
112 void setStartLineNumber(int32_t line
);
113 void setEndLineNumber(int32_t line
);
115 void removeWhitespace(bool stripAll
=true, const char** cDataTags
=NULL
);
117 status_t
parseValues(const sp
<AaptAssets
>& assets
, ResourceTable
* table
);
119 status_t
assignResourceIds(const sp
<AaptAssets
>& assets
,
120 const ResourceTable
* table
= NULL
);
122 status_t
flatten(const sp
<AaptFile
>& dest
, bool stripComments
,
123 bool stripRawValues
) const;
125 void print(int indent
=0);
133 Vector
<sp
<XMLNode
> > stack
;
134 String16 pendingComment
;
138 startNamespace(void *userData
, const char *prefix
, const char *uri
);
140 startElement(void *userData
, const char *name
, const char **atts
);
142 characterData(void *userData
, const XML_Char
*s
, int len
);
144 endElement(void *userData
, const char *name
);
146 endNamespace(void *userData
, const char *prefix
);
149 commentData(void *userData
, const char *comment
);
151 // Creating an element node.
152 XMLNode(const String8
& filename
, const String16
& s1
, const String16
& s2
, bool isNamespace
);
154 // Creating a CDATA node.
155 XMLNode(const String8
& filename
);
157 status_t
collect_strings(StringPool
* dest
, Vector
<uint32_t>* outResIds
,
158 bool stripComments
, bool stripRawValues
) const;
160 status_t
collect_attr_strings(StringPool
* outPool
,
161 Vector
<uint32_t>* outResIds
, bool allAttrs
) const;
163 status_t
collect_resid_strings(StringPool
* outPool
,
164 Vector
<uint32_t>* outResIds
) const;
166 status_t
flatten_node(const StringPool
& strings
, const sp
<AaptFile
>& dest
,
167 bool stripComments
, bool stripRawValues
) const;
169 String16 mNamespacePrefix
;
170 String16 mNamespaceUri
;
171 String16 mElementName
;
172 Vector
<sp
<XMLNode
> > mChildren
;
173 Vector
<attribute_entry
> mAttributes
;
174 KeyedVector
<uint32_t, uint32_t> mAttributeOrder
;
175 uint32_t mNextAttributeIndex
;
177 Res_value mCharsValue
;
180 int32_t mStartLineNumber
;
181 int32_t mEndLineNumber
;