• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2017 PDFium Authors. All rights reserved.
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 <utility>
10 
11 #include "core/fxcrt/fx_codepage.h"
12 #include "core/fxcrt/fx_extension.h"
13 #include "core/fxcrt/xml/cfx_xmldocument.h"
14 
CFX_XMLInstruction(const WideString & wsTarget)15 CFX_XMLInstruction::CFX_XMLInstruction(const WideString& wsTarget)
16     : name_(wsTarget) {}
17 
18 CFX_XMLInstruction::~CFX_XMLInstruction() = default;
19 
GetType() const20 CFX_XMLNode::Type CFX_XMLInstruction::GetType() const {
21   return Type::kInstruction;
22 }
23 
Clone(CFX_XMLDocument * doc)24 CFX_XMLNode* CFX_XMLInstruction::Clone(CFX_XMLDocument* doc) {
25   auto* node = doc->CreateNode<CFX_XMLInstruction>(name_);
26   node->target_data_ = target_data_;
27   return node;
28 }
29 
AppendData(const WideString & wsData)30 void CFX_XMLInstruction::AppendData(const WideString& wsData) {
31   target_data_.push_back(wsData);
32 }
33 
IsOriginalXFAVersion() const34 bool CFX_XMLInstruction::IsOriginalXFAVersion() const {
35   return name_.EqualsASCII("originalXFAVersion");
36 }
37 
IsAcrobat() const38 bool CFX_XMLInstruction::IsAcrobat() const {
39   return name_.EqualsASCII("acrobat");
40 }
41 
Save(const RetainPtr<IFX_SeekableWriteStream> & pXMLStream)42 void CFX_XMLInstruction::Save(
43     const RetainPtr<IFX_SeekableWriteStream>& pXMLStream) {
44   if (name_.EqualsASCIINoCase("xml")) {
45     pXMLStream->WriteString("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
46     return;
47   }
48 
49   pXMLStream->WriteString("<?");
50   pXMLStream->WriteString(name_.ToUTF8().AsStringView());
51   pXMLStream->WriteString(" ");
52 
53   for (const WideString& target : target_data_) {
54     pXMLStream->WriteString(target.ToUTF8().AsStringView());
55     pXMLStream->WriteString(" ");
56   }
57 
58   pXMLStream->WriteString("?>\n");
59 }
60