1 // Copyright 2017 The PDFium Authors 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com 6 7 #include "core/fxcrt/xml/cfx_xmlinstruction.h" 8 9 #include "core/fxcrt/fx_codepage.h" 10 #include "core/fxcrt/fx_extension.h" 11 #include "core/fxcrt/xml/cfx_xmldocument.h" 12 CFX_XMLInstruction(const WideString & wsTarget)13CFX_XMLInstruction::CFX_XMLInstruction(const WideString& wsTarget) 14 : name_(wsTarget) {} 15 16 CFX_XMLInstruction::~CFX_XMLInstruction() = default; 17 GetType() const18CFX_XMLNode::Type CFX_XMLInstruction::GetType() const { 19 return Type::kInstruction; 20 } 21 Clone(CFX_XMLDocument * doc)22CFX_XMLNode* CFX_XMLInstruction::Clone(CFX_XMLDocument* doc) { 23 auto* node = doc->CreateNode<CFX_XMLInstruction>(name_); 24 node->target_data_ = target_data_; 25 return node; 26 } 27 AppendData(const WideString & wsData)28void CFX_XMLInstruction::AppendData(const WideString& wsData) { 29 target_data_.push_back(wsData); 30 } 31 IsOriginalXFAVersion() const32bool CFX_XMLInstruction::IsOriginalXFAVersion() const { 33 return name_.EqualsASCII("originalXFAVersion"); 34 } 35 IsAcrobat() const36bool CFX_XMLInstruction::IsAcrobat() const { 37 return name_.EqualsASCII("acrobat"); 38 } 39 Save(const RetainPtr<IFX_RetainableWriteStream> & pXMLStream)40void CFX_XMLInstruction::Save( 41 const RetainPtr<IFX_RetainableWriteStream>& pXMLStream) { 42 if (name_.EqualsASCIINoCase("xml")) { 43 pXMLStream->WriteString("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"); 44 return; 45 } 46 47 pXMLStream->WriteString("<?"); 48 pXMLStream->WriteString(name_.ToUTF8().AsStringView()); 49 pXMLStream->WriteString(" "); 50 51 for (const WideString& target : target_data_) { 52 pXMLStream->WriteString(target.ToUTF8().AsStringView()); 53 pXMLStream->WriteString(" "); 54 } 55 56 pXMLStream->WriteString("?>\n"); 57 } 58