X-Git-Url: https://git.saurik.com/android/aapt.git/blobdiff_plain/d284bd5142dc1ae7ed2396a6cd0eefcaa2a65264..e518e42d97b482ada2a3b325dcbfd4a0c6133a80:/XMLNode.cpp diff --git a/XMLNode.cpp b/XMLNode.cpp index cee8546..0dba950 100644 --- a/XMLNode.cpp +++ b/XMLNode.cpp @@ -21,6 +21,7 @@ const char* const RESOURCES_ROOT_NAMESPACE = "http://schemas.android.com/apk/res/"; const char* const RESOURCES_ANDROID_NAMESPACE = "http://schemas.android.com/apk/res/android"; +const char* const RESOURCES_AUTO_PACKAGE_NAMESPACE = "http://schemas.android.com/apk/res-auto"; const char* const RESOURCES_ROOT_PRV_NAMESPACE = "http://schemas.android.com/apk/prv/res/"; const char* const XLIFF_XMLNS = "urn:oasis:names:tc:xliff:document:1.2"; @@ -44,15 +45,21 @@ bool isWhitespace(const char16_t* str) } static const String16 RESOURCES_PREFIX(RESOURCES_ROOT_NAMESPACE); +static const String16 RESOURCES_PREFIX_AUTO_PACKAGE(RESOURCES_AUTO_PACKAGE_NAMESPACE); static const String16 RESOURCES_PRV_PREFIX(RESOURCES_ROOT_PRV_NAMESPACE); +static const String16 RESOURCES_TOOLS_NAMESPACE("http://schemas.android.com/tools"); -String16 getNamespaceResourcePackage(String16 namespaceUri, bool* outIsPublic) +String16 getNamespaceResourcePackage(String16 appPackage, String16 namespaceUri, bool* outIsPublic) { //printf("%s starts with %s?\n", String8(namespaceUri).string(), // String8(RESOURCES_PREFIX).string()); size_t prefixSize; bool isPublic = true; - if (namespaceUri.startsWith(RESOURCES_PREFIX)) { + if(namespaceUri.startsWith(RESOURCES_PREFIX_AUTO_PACKAGE)) { + NOISY(printf("Using default application package: %s -> %s\n", String8(namespaceUri).string(), String8(appPackage).string())); + isPublic = true; + return appPackage; + } else if (namespaceUri.startsWith(RESOURCES_PREFIX)) { prefixSize = RESOURCES_PREFIX.size(); } else if (namespaceUri.startsWith(RESOURCES_PRV_PREFIX)) { isPublic = false; @@ -203,13 +210,9 @@ status_t parseStyledString(Bundle* bundle, } } if (xliffDepth == 0 && pseudolocalize) { -#ifdef ENABLE_PSEUDOLOCALIZE std::string orig(String8(text).string()); std::string pseudo = pseudolocalize_string(orig); curString.append(String16(String8(pseudo.c_str()))); -#else - assert(false); -#endif } else { if (isFormatted && hasSubstitutionErrors(fileName, inXml, text) != NO_ERROR) { return UNKNOWN_ERROR; @@ -455,13 +458,15 @@ void printXMLBlock(ResXMLTree* block) printf("=?0x%x", (int)value.data); } else if (value.dataType == Res_value::TYPE_STRING) { printf("=\"%s\"", - String8(block->getAttributeStringValue(i, &len)).string()); + ResTable::normalizeForOutput(String8(block->getAttributeStringValue(i, + &len)).string()).string()); } else { printf("=(type 0x%x)0x%x", (int)value.dataType, (int)value.data); } const char16_t* val = block->getAttributeStringValue(i, &len); if (val != NULL) { - printf(" (Raw: \"%s\")", String8(val).string()); + printf(" (Raw: \"%s\")", ResTable::normalizeForOutput(String8(val).string()). + string()); } printf("\n"); } @@ -763,13 +768,16 @@ status_t XMLNode::addAttribute(const String16& ns, const String16& name, SourcePos(mFilename, getStartLineNumber()).error("Child to CDATA node."); return UNKNOWN_ERROR; } - attribute_entry e; - e.index = mNextAttributeIndex++; - e.ns = ns; - e.name = name; - e.string = value; - mAttributes.add(e); - mAttributeOrder.add(e.index, mAttributes.size()-1); + + if (ns != RESOURCES_TOOLS_NAMESPACE) { + attribute_entry e; + e.index = mNextAttributeIndex++; + e.ns = ns; + e.name = name; + e.string = value; + mAttributes.add(e); + mAttributeOrder.add(e.index, mAttributes.size()-1); + } return NO_ERROR; } @@ -924,7 +932,7 @@ status_t XMLNode::assignResourceIds(const sp& assets, const attribute_entry& e = mAttributes.itemAt(i); if (e.ns.size() <= 0) continue; bool nsIsPublic; - String16 pkg(getNamespaceResourcePackage(e.ns, &nsIsPublic)); + String16 pkg(getNamespaceResourcePackage(String16(assets->getPackage()), e.ns, &nsIsPublic)); NOISY(printf("Elem %s %s=\"%s\": namespace(%s) %s ===> %s\n", String8(getElementName()).string(), String8(e.name).string(), @@ -965,7 +973,7 @@ status_t XMLNode::assignResourceIds(const sp& assets, status_t XMLNode::flatten(const sp& dest, bool stripComments, bool stripRawValues) const { - StringPool strings = StringPool(false, mUTF8); + StringPool strings(mUTF8); Vector resids; // First collect just the strings for attribute names that have a @@ -1217,11 +1225,13 @@ status_t XMLNode::collect_strings(StringPool* dest, Vector* outResIds, collect_attr_strings(dest, outResIds, true); int i; - if (mNamespacePrefix.size() > 0) { - dest->add(mNamespacePrefix, true); - } - if (mNamespaceUri.size() > 0) { - dest->add(mNamespaceUri, true); + if (RESOURCES_TOOLS_NAMESPACE != mNamespaceUri) { + if (mNamespacePrefix.size() > 0) { + dest->add(mNamespacePrefix, true); + } + if (mNamespaceUri.size() > 0) { + dest->add(mNamespaceUri, true); + } } if (mElementName.size() > 0) { dest->add(mElementName, true); @@ -1340,6 +1350,7 @@ status_t XMLNode::flatten_node(const StringPool& strings, const sp& de const void* extData = NULL; size_t extSize = 0; ResXMLTree_attribute attr; + bool writeCurrentNode = true; const size_t NA = mAttributes.size(); const size_t NC = mChildren.size(); @@ -1352,7 +1363,7 @@ status_t XMLNode::flatten_node(const StringPool& strings, const sp& de const String16 style16("style"); const type type = getType(); - + memset(&node, 0, sizeof(node)); memset(&attr, 0, sizeof(attr)); node.header.headerSize = htods(sizeof(node)); @@ -1397,17 +1408,21 @@ status_t XMLNode::flatten_node(const StringPool& strings, const sp& de } } } else if (type == TYPE_NAMESPACE) { - node.header.type = htods(RES_XML_START_NAMESPACE_TYPE); - extData = &namespaceExt; - extSize = sizeof(namespaceExt); - memset(&namespaceExt, 0, sizeof(namespaceExt)); - if (mNamespacePrefix.size() > 0) { - namespaceExt.prefix.index = htodl(strings.offsetForString(mNamespacePrefix)); + if (mNamespaceUri == RESOURCES_TOOLS_NAMESPACE) { + writeCurrentNode = false; } else { - namespaceExt.prefix.index = htodl((uint32_t)-1); + node.header.type = htods(RES_XML_START_NAMESPACE_TYPE); + extData = &namespaceExt; + extSize = sizeof(namespaceExt); + memset(&namespaceExt, 0, sizeof(namespaceExt)); + if (mNamespacePrefix.size() > 0) { + namespaceExt.prefix.index = htodl(strings.offsetForString(mNamespacePrefix)); + } else { + namespaceExt.prefix.index = htodl((uint32_t)-1); + } + namespaceExt.prefix.index = htodl(strings.offsetForString(mNamespacePrefix)); + namespaceExt.uri.index = htodl(strings.offsetForString(mNamespaceUri)); } - namespaceExt.prefix.index = htodl(strings.offsetForString(mNamespacePrefix)); - namespaceExt.uri.index = htodl(strings.offsetForString(mNamespaceUri)); LOG_ALWAYS_FATAL_IF(NA != 0, "Namespace nodes can't have attributes!"); } else if (type == TYPE_CDATA) { node.header.type = htods(RES_XML_CDATA_TYPE); @@ -1424,9 +1439,11 @@ status_t XMLNode::flatten_node(const StringPool& strings, const sp& de node.header.size = htodl(sizeof(node) + extSize + (sizeof(attr)*NA)); - dest->writeData(&node, sizeof(node)); - if (extSize > 0) { - dest->writeData(extData, extSize); + if (writeCurrentNode) { + dest->writeData(&node, sizeof(node)); + if (extSize > 0) { + dest->writeData(extData, extSize); + } } for (i=0; i& de dest->writeData(&node, sizeof(node)); dest->writeData(&endElementExt, sizeof(endElementExt)); } else if (type == TYPE_NAMESPACE) { - node.header.type = htods(RES_XML_END_NAMESPACE_TYPE); - node.lineNumber = htodl(getEndLineNumber()); - node.comment.index = htodl((uint32_t)-1); - node.header.size = htodl(sizeof(node)+extSize); - dest->writeData(&node, sizeof(node)); - dest->writeData(extData, extSize); + if (writeCurrentNode) { + node.header.type = htods(RES_XML_END_NAMESPACE_TYPE); + node.lineNumber = htodl(getEndLineNumber()); + node.comment.index = htodl((uint32_t)-1); + node.header.size = htodl(sizeof(node)+extSize); + dest->writeData(&node, sizeof(node)); + dest->writeData(extData, extSize); + } } return NO_ERROR;