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
,
29 bool isPseudolocalizable
);
31 void printXMLBlock(ResXMLTree
* block
);
33 status_t
parseXMLResource(const sp
<AaptFile
>& file
, ResXMLTree
* outTree
,
34 bool stripAll
=true, bool keepComments
=false,
35 const char** cDataTags
=NULL
);
37 class XMLNode
: public RefBase
40 static sp
<XMLNode
> parse(const sp
<AaptFile
>& file
);
43 sp
<XMLNode
> newNamespace(const String8
& filename
, const String16
& prefix
, const String16
& uri
) {
44 return new XMLNode(filename
, prefix
, uri
, true);
48 sp
<XMLNode
> newElement(const String8
& filename
, const String16
& ns
, const String16
& name
) {
49 return new XMLNode(filename
, ns
, name
, false);
53 sp
<XMLNode
> newCData(const String8
& filename
) {
54 return new XMLNode(filename
);
65 const String16
& getNamespacePrefix() const;
66 const String16
& getNamespaceUri() const;
68 const String16
& getElementNamespace() const;
69 const String16
& getElementName() const;
70 const Vector
<sp
<XMLNode
> >& getChildren() const;
72 const String8
& getFilename() const;
74 struct attribute_entry
{
75 attribute_entry() : index(~(uint32_t)0), nameResId(0)
77 value
.dataType
= Res_value::TYPE_NULL
;
80 bool needStringValue() const {
82 || value
.dataType
== Res_value::TYPE_NULL
83 || value
.dataType
== Res_value::TYPE_STRING
;
92 mutable uint32_t namePoolIdx
;
95 const Vector
<attribute_entry
>& getAttributes() const;
97 const attribute_entry
* getAttribute(const String16
& ns
, const String16
& name
) const;
99 attribute_entry
* editAttribute(const String16
& ns
, const String16
& name
);
101 const String16
& getCData() const;
103 const String16
& getComment() const;
105 int32_t getStartLineNumber() const;
106 int32_t getEndLineNumber() const;
108 sp
<XMLNode
> searchElement(const String16
& tagNamespace
, const String16
& tagName
);
110 sp
<XMLNode
> getChildElement(const String16
& tagNamespace
, const String16
& tagName
);
112 status_t
addChild(const sp
<XMLNode
>& child
);
114 status_t
insertChildAt(const sp
<XMLNode
>& child
, size_t index
);
116 status_t
addAttribute(const String16
& ns
, const String16
& name
,
117 const String16
& value
);
119 void setAttributeResID(size_t attrIdx
, uint32_t resId
);
121 status_t
appendChars(const String16
& chars
);
123 status_t
appendComment(const String16
& comment
);
125 void setStartLineNumber(int32_t line
);
126 void setEndLineNumber(int32_t line
);
128 void removeWhitespace(bool stripAll
=true, const char** cDataTags
=NULL
);
130 void setUTF8(bool val
) { mUTF8
= val
; }
132 status_t
parseValues(const sp
<AaptAssets
>& assets
, ResourceTable
* table
);
134 status_t
assignResourceIds(const sp
<AaptAssets
>& assets
,
135 const ResourceTable
* table
= NULL
);
137 status_t
flatten(const sp
<AaptFile
>& dest
, bool stripComments
,
138 bool stripRawValues
) const;
140 void print(int indent
=0);
148 Vector
<sp
<XMLNode
> > stack
;
149 String16 pendingComment
;
153 startNamespace(void *userData
, const char *prefix
, const char *uri
);
155 startElement(void *userData
, const char *name
, const char **atts
);
157 characterData(void *userData
, const XML_Char
*s
, int len
);
159 endElement(void *userData
, const char *name
);
161 endNamespace(void *userData
, const char *prefix
);
164 commentData(void *userData
, const char *comment
);
166 // Creating an element node.
167 XMLNode(const String8
& filename
, const String16
& s1
, const String16
& s2
, bool isNamespace
);
169 // Creating a CDATA node.
170 XMLNode(const String8
& filename
);
172 status_t
collect_strings(StringPool
* dest
, Vector
<uint32_t>* outResIds
,
173 bool stripComments
, bool stripRawValues
) const;
175 status_t
collect_attr_strings(StringPool
* outPool
,
176 Vector
<uint32_t>* outResIds
, bool allAttrs
) const;
178 status_t
collect_resid_strings(StringPool
* outPool
,
179 Vector
<uint32_t>* outResIds
) const;
181 status_t
flatten_node(const StringPool
& strings
, const sp
<AaptFile
>& dest
,
182 bool stripComments
, bool stripRawValues
) const;
184 String16 mNamespacePrefix
;
185 String16 mNamespaceUri
;
186 String16 mElementName
;
187 Vector
<sp
<XMLNode
> > mChildren
;
188 Vector
<attribute_entry
> mAttributes
;
189 KeyedVector
<uint32_t, uint32_t> mAttributeOrder
;
190 uint32_t mNextAttributeIndex
;
192 Res_value mCharsValue
;
195 int32_t mStartLineNumber
;
196 int32_t mEndLineNumber
;
198 // Encode compiled XML with UTF-8 StringPools?