1 // Copyright 2014 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 #ifndef _FDE_XML 8 #define _FDE_XML 9 class IFDE_XMLNode; 10 class IFDE_XMLInstruction; 11 class IFDE_XMLDeclaration; 12 class IFDE_XMLDeclComment; 13 class IFDE_XMLDeclCharData; 14 class IFDE_XMLDeclDocType; 15 class IFDE_XMLDeclElement; 16 class IFDE_XMLDeclAttriList; 17 class IFDE_XMLDeclNotition; 18 class IFDE_XMLDeclEntity; 19 class IFDE_XMLElement; 20 class IFDE_XMLText; 21 class IFDE_XMLDoc; 22 class IFDE_XMLParser; 23 class IFDE_XMLSyntaxParser; 24 #ifdef __cplusplus 25 extern "C" { 26 #endif 27 enum FDE_XMLNODETYPE { 28 FDE_XMLNODE_Unknown = 0, 29 FDE_XMLNODE_Instruction, 30 FDE_XMLNODE_Element, 31 FDE_XMLNODE_Text, 32 FDE_XMLNODE_CharData, 33 }; 34 typedef struct _FDE_XMLNODE { 35 int32_t iNodeNum; 36 FDE_XMLNODETYPE eNodeType; 37 } FDE_XMLNODE, *FDE_LPXMLNODE; 38 typedef FDE_XMLNODE const* FDE_LPCXMLNODE; 39 typedef CFX_StackTemplate<FDE_XMLNODE> CFDE_XMLNodeStack; 40 FX_BOOL FDE_IsXMLValidChar(FX_WCHAR ch); 41 FX_BOOL FDE_IsXMLWhiteSpace(FX_WCHAR ch); 42 FX_BOOL FDE_IsXMLNameChar(FX_WCHAR ch, FX_BOOL bFirstChar); 43 #ifdef __cplusplus 44 } 45 #endif 46 47 class IFDE_XMLNode { 48 public: ~IFDE_XMLNode()49 virtual ~IFDE_XMLNode() {} 50 virtual void Release() = 0; 51 virtual FDE_XMLNODETYPE GetType() const = 0; 52 virtual int32_t CountChildNodes() const = 0; 53 virtual IFDE_XMLNode* GetChildNode(int32_t index) const = 0; 54 virtual int32_t GetChildNodeIndex(IFDE_XMLNode* pNode) const = 0; 55 virtual IFDE_XMLNode* GetPath(const FX_WCHAR* pPath, 56 int32_t iLength = -1, 57 FX_BOOL bQualifiedName = TRUE) const = 0; 58 virtual int32_t InsertChildNode(IFDE_XMLNode* pNode, int32_t index = -1) = 0; 59 virtual void RemoveChildNode(IFDE_XMLNode* pNode) = 0; 60 virtual void DeleteChildren() = 0; 61 enum NodeItem { 62 Root = 0, 63 Parent, 64 FirstSibling, 65 PriorSibling, 66 NextSibling, 67 LastSibling, 68 FirstNeighbor, 69 PriorNeighbor, 70 NextNeighbor, 71 LastNeighbor, 72 FirstChild, 73 LastChild 74 }; 75 virtual IFDE_XMLNode* GetNodeItem(NodeItem eItem) const = 0; 76 virtual int32_t GetNodeLevel() const = 0; 77 virtual FX_BOOL InsertNodeItem(IFDE_XMLNode::NodeItem eItem, 78 IFDE_XMLNode* pNode) = 0; 79 virtual IFDE_XMLNode* RemoveNodeItem(IFDE_XMLNode::NodeItem eItem) = 0; 80 virtual IFDE_XMLNode* Clone(FX_BOOL bRecursive) = 0; 81 virtual void SaveXMLNode(IFX_Stream* pXMLStream) = 0; 82 }; 83 class IFDE_XMLInstruction : public IFDE_XMLNode { 84 public: 85 static IFDE_XMLInstruction* Create(const CFX_WideString& wsTarget); 86 virtual void GetTargetName(CFX_WideString& wsTarget) const = 0; 87 virtual int32_t CountAttributes() const = 0; 88 virtual FX_BOOL GetAttribute(int32_t index, 89 CFX_WideString& wsAttriName, 90 CFX_WideString& wsAttriValue) const = 0; 91 virtual FX_BOOL HasAttribute(const FX_WCHAR* pwsAttriName) const = 0; 92 virtual void GetString(const FX_WCHAR* pwsAttriName, 93 CFX_WideString& wsAttriValue, 94 const FX_WCHAR* pwsDefValue = NULL) const = 0; 95 virtual void SetString(const CFX_WideString& wsAttriName, 96 const CFX_WideString& wsAttriValue) = 0; 97 virtual int32_t GetInteger(const FX_WCHAR* pwsAttriName, 98 int32_t iDefValue = 0) const = 0; 99 virtual void SetInteger(const FX_WCHAR* pwsAttriName, 100 int32_t iAttriValue) = 0; 101 virtual FX_FLOAT GetFloat(const FX_WCHAR* pwsAttriName, 102 FX_FLOAT fDefValue = 0) const = 0; 103 virtual void SetFloat(const FX_WCHAR* pwsAttriName, FX_FLOAT fAttriValue) = 0; 104 virtual void RemoveAttribute(const FX_WCHAR* pwsAttriName) = 0; 105 virtual int32_t CountData() const = 0; 106 virtual FX_BOOL GetData(int32_t index, CFX_WideString& wsData) const = 0; 107 virtual void AppendData(const CFX_WideString& wsData) = 0; 108 virtual void RemoveData(int32_t index) = 0; 109 }; 110 class IFDE_XMLElement : public IFDE_XMLNode { 111 public: 112 static IFDE_XMLElement* Create(const CFX_WideString& wsTag); 113 virtual void GetTagName(CFX_WideString& wsTag) const = 0; 114 virtual void GetLocalTagName(CFX_WideString& wsTag) const = 0; 115 virtual void GetNamespacePrefix(CFX_WideString& wsPrefix) const = 0; 116 virtual void GetNamespaceURI(CFX_WideString& wsNamespace) const = 0; 117 virtual int32_t CountAttributes() const = 0; 118 virtual FX_BOOL GetAttribute(int32_t index, 119 CFX_WideString& wsAttriName, 120 CFX_WideString& wsAttriValue) const = 0; 121 virtual FX_BOOL HasAttribute(const FX_WCHAR* pwsAttriName) const = 0; 122 virtual void GetString(const FX_WCHAR* pwsAttriName, 123 CFX_WideString& wsAttriValue, 124 const FX_WCHAR* pwsDefValue = NULL) const = 0; 125 virtual void SetString(const CFX_WideString& wsAttriName, 126 const CFX_WideString& wsAttriValue) = 0; 127 virtual int32_t GetInteger(const FX_WCHAR* pwsAttriName, 128 int32_t iDefValue = 0) const = 0; 129 virtual void SetInteger(const FX_WCHAR* pwsAttriName, 130 int32_t iAttriValue) = 0; 131 virtual FX_FLOAT GetFloat(const FX_WCHAR* pwsAttriName, 132 FX_FLOAT fDefValue = 0) const = 0; 133 virtual void SetFloat(const FX_WCHAR* pwsAttriName, FX_FLOAT fAttriValue) = 0; 134 virtual void RemoveAttribute(const FX_WCHAR* pwsAttriName) = 0; 135 virtual void GetTextData(CFX_WideString& wsText) const = 0; 136 virtual void SetTextData(const CFX_WideString& wsText) = 0; 137 }; 138 class IFDE_XMLText : public IFDE_XMLNode { 139 public: 140 static IFDE_XMLText* Create(const CFX_WideString& wsText); 141 virtual void GetText(CFX_WideString& wsText) const = 0; 142 virtual void SetText(const CFX_WideString& wsText) = 0; 143 }; 144 class IFDE_XMLDeclaration : public IFDE_XMLNode { 145 public: 146 }; 147 class IFDE_XMLCharData : public IFDE_XMLDeclaration { 148 public: 149 static IFDE_XMLCharData* Create(const CFX_WideString& wsCData); ~IFDE_XMLCharData()150 virtual ~IFDE_XMLCharData() {} 151 152 virtual void GetCharData(CFX_WideString& wsCData) const = 0; 153 virtual void SetCharData(const CFX_WideString& wsCData) = 0; 154 }; 155 typedef struct _FDE_XMLREADERHANDLER { 156 void* pData; 157 158 void (*OnTagEnter)(_FDE_XMLREADERHANDLER* pThis, 159 FDE_XMLNODETYPE eType, 160 const CFX_WideString& wsTagName); 161 void (*OnTagBreak)(_FDE_XMLREADERHANDLER* pThis, 162 const CFX_WideString& wsTagName); 163 void (*OnTagClose)(_FDE_XMLREADERHANDLER* pThis, 164 const CFX_WideString& wsTagName); 165 void (*OnAttribute)(_FDE_XMLREADERHANDLER* pThis, 166 const CFX_WideString& wsName, 167 const CFX_WideString& wsValue); 168 void (*OnData)(_FDE_XMLREADERHANDLER* pThis, 169 FDE_XMLNODETYPE eType, 170 const CFX_WideString& wsValue); 171 } FDE_XMLREADERHANDLER, *FDE_LPXMLREADERHANDLER; 172 class IFDE_XMLDoc { 173 public: 174 static IFDE_XMLDoc* Create(); ~IFDE_XMLDoc()175 virtual ~IFDE_XMLDoc() {} 176 virtual void Release() = 0; 177 virtual FX_BOOL LoadXML(IFX_Stream* pXMLStream, 178 int32_t iXMLPlaneSize = 8192, 179 int32_t iTextDataSize = 256, 180 FDE_LPXMLREADERHANDLER pHandler = NULL) = 0; 181 virtual FX_BOOL LoadXML(IFDE_XMLParser* pXMLParser) = 0; 182 virtual int32_t DoLoad(IFX_Pause* pPause = NULL) = 0; 183 virtual void CloseXML() = 0; 184 virtual IFDE_XMLNode* GetRoot() const = 0; 185 virtual void SaveXML(IFX_Stream* pXMLStream = NULL, 186 FX_BOOL bSaveBOM = TRUE) = 0; 187 virtual void SaveXMLNode(IFX_Stream* pXMLStream, IFDE_XMLNode* pNode) = 0; 188 }; 189 class IFDE_XMLParser { 190 public: ~IFDE_XMLParser()191 virtual ~IFDE_XMLParser() {} 192 virtual void Release() = 0; 193 virtual int32_t DoParser(IFX_Pause* pPause) = 0; 194 }; 195 #define FDE_XMLSYNTAXSTATUS_None 0x00 196 #define FDE_XMLSYNTAXSTATUS_InstructionOpen 0x01 197 #define FDE_XMLSYNTAXSTATUS_InstructionClose 0x02 198 #define FDE_XMLSYNTAXSTATUS_ElementOpen 0x03 199 #define FDE_XMLSYNTAXSTATUS_ElementBreak 0x04 200 #define FDE_XMLSYNTAXSTATUS_ElementClose 0x05 201 #define FDE_XMLSYNTAXSTATUS_TargetName 0x06 202 #define FDE_XMLSYNTAXSTATUS_TagName 0x07 203 #define FDE_XMLSYNTAXSTATUS_AttriName 0x08 204 #define FDE_XMLSYNTAXSTATUS_AttriValue 0x09 205 #define FDE_XMLSYNTAXSTATUS_Text 0x0A 206 #define FDE_XMLSYNTAXSTATUS_CData 0x0B 207 #define FDE_XMLSYNTAXSTATUS_TargetData 0x0C 208 #define FDE_XMLSYNTAXSTATUS_Error 0xFE 209 #define FDE_XMLSYNTAXSTATUS_EOS 0xFF 210 class IFDE_XMLSyntaxParser { 211 public: 212 static IFDE_XMLSyntaxParser* Create(); ~IFDE_XMLSyntaxParser()213 virtual ~IFDE_XMLSyntaxParser() {} 214 virtual void Release() = 0; 215 virtual void Init(IFX_Stream* pStream, 216 int32_t iXMLPlaneSize, 217 int32_t iTextDataSize = 256) = 0; 218 virtual FX_DWORD DoSyntaxParse() = 0; 219 virtual int32_t GetStatus() const = 0; 220 virtual int32_t GetCurrentPos() const = 0; 221 virtual FX_FILESIZE GetCurrentBinaryPos() const = 0; 222 virtual int32_t GetCurrentNodeNumber() const = 0; 223 virtual int32_t GetLastNodeNumber() const = 0; 224 virtual void GetTargetName(CFX_WideString& wsTarget) const = 0; 225 virtual void GetTagName(CFX_WideString& wsTag) const = 0; 226 virtual void GetAttributeName(CFX_WideString& wsAttriName) const = 0; 227 virtual void GetAttributeValue(CFX_WideString& wsAttriValue) const = 0; 228 virtual void GetTextData(CFX_WideString& wsText) const = 0; 229 virtual void GetTargetData(CFX_WideString& wsData) const = 0; 230 }; 231 #endif 232