void CFX_XMLElement::Save( const RetainPtr<IFX_SeekableWriteStream>& pXMLStream) { ByteString bsNameEncoded = name_.ToUTF8(); pXMLStream->WriteString("<"); pXMLStream->WriteString(bsNameEncoded.AsStringView()); for (auto it : attrs_) { // Note, the space between attributes is added by AttributeToString which // writes a blank as the first character. pXMLStream->WriteString( AttributeToString(it.first, it.second).ToUTF8().AsStringView()); } if (!GetFirstChild()) { pXMLStream->WriteString(" />\n"); return; } pXMLStream->WriteString(">\n"); for (CFX_XMLNode* pChild = GetFirstChild(); pChild; pChild = pChild->GetNextSibling()) { pChild->Save(pXMLStream); } pXMLStream->WriteString("</"); pXMLStream->WriteString(bsNameEncoded.AsStringView()); pXMLStream->WriteString(">\n"); }
WideString CFX_XMLElement::GetTextData() const { CFX_WideTextBuf buffer; for (CFX_XMLNode* pChild = GetFirstChild(); pChild; pChild = pChild->GetNextSibling()) { CFX_XMLText* pText = ToXMLText(pChild); if (pText) buffer << pText->GetText(); } return buffer.MakeString(); }
CFX_XMLNode* CFX_XMLElement::Clone(CFX_XMLDocument* doc) { auto* node = doc->CreateNode<CFX_XMLElement>(name_); node->attrs_ = attrs_; // TODO(dsinclair): This clone is wrong. It doesn't clone all child nodes just // text nodes? for (CFX_XMLNode* pChild = GetFirstChild(); pChild; pChild = pChild->GetNextSibling()) { if (pChild->GetType() == FX_XMLNODE_Text) node->AppendChild(pChild->Clone(doc)); } return node; }
CXFA_Node* CXFA_TextProvider::GetTextNode(bool& bRichText) { bRichText = false; if (m_eType == XFA_TEXTPROVIDERTYPE_Text) { CXFA_Value* pValueNode = m_pNode->GetChild<CXFA_Value>(0, XFA_Element::Value, false); if (!pValueNode) return nullptr; CXFA_Node* pChildNode = pValueNode->GetFirstChild(); if (pChildNode && pChildNode->GetElementType() == XFA_Element::ExData) { Optional<WideString> contentType = pChildNode->JSObject()->TryAttribute( XFA_Attribute::ContentType, false); if (contentType.has_value() && contentType.value().EqualsASCII("text/html")) { bRichText = true; } } return pChildNode; } if (m_eType == XFA_TEXTPROVIDERTYPE_Datasets) { CXFA_Node* pBind = m_pNode->GetBindData(); CFX_XMLNode* pXMLNode = pBind->GetXMLMappingNode(); for (CFX_XMLNode* pXMLChild = pXMLNode->GetFirstChild(); pXMLChild; pXMLChild = pXMLChild->GetNextSibling()) { CFX_XMLElement* pElement = ToXMLElement(pXMLChild); if (pElement && XFA_RecognizeRichText(pElement)) { bRichText = true; break; } } return pBind; } if (m_eType == XFA_TEXTPROVIDERTYPE_Caption) { CXFA_Caption* pCaptionNode = m_pNode->GetChild<CXFA_Caption>(0, XFA_Element::Caption, false); if (!pCaptionNode) return nullptr; CXFA_Value* pValueNode = pCaptionNode->GetChild<CXFA_Value>(0, XFA_Element::Value, false); if (!pValueNode) return nullptr; CXFA_Node* pChildNode = pValueNode->GetFirstChild(); if (pChildNode && pChildNode->GetElementType() == XFA_Element::ExData) { Optional<WideString> contentType = pChildNode->JSObject()->TryAttribute( XFA_Attribute::ContentType, false); if (contentType.has_value() && contentType.value().EqualsASCII("text/html")) { bRichText = true; } } return pChildNode; } CXFA_Items* pItemNode = m_pNode->GetChild<CXFA_Items>(0, XFA_Element::Items, false); if (!pItemNode) return nullptr; CXFA_Node* pNode = pItemNode->GetFirstChild(); while (pNode) { WideString wsName = pNode->JSObject()->GetCData(XFA_Attribute::Name); if (m_eType == XFA_TEXTPROVIDERTYPE_Rollover && wsName.EqualsASCII("rollover")) { return pNode; } if (m_eType == XFA_TEXTPROVIDERTYPE_Down && wsName.EqualsASCII("down")) return pNode; pNode = pNode->GetNextSibling(); } return nullptr; }