| OLD | NEW |
| (Empty) |
| 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 XFA_SRC_FDE_XML_FDE_XML_IMP_H_ | |
| 8 #define XFA_SRC_FDE_XML_FDE_XML_IMP_H_ | |
| 9 | |
| 10 #include "core/include/fxcrt/fx_system.h" | |
| 11 #include "xfa/src/fde/xml/fde_xml.h" | |
| 12 #include "xfa/src/fgas/crt/fgas_memory.h" | |
| 13 #include "xfa/src/fgas/crt/fgas_stream.h" | |
| 14 | |
| 15 class CFDE_BlockBuffer; | |
| 16 class CFDE_XMLInstruction; | |
| 17 class CFDE_XMLElement; | |
| 18 class CFDE_XMLText; | |
| 19 class CFDE_XMLDoc; | |
| 20 class IFDE_XMLParser; | |
| 21 class CFDE_XMLDOMParser; | |
| 22 class CFDE_XMLSAXParser; | |
| 23 class CFDE_XMLSyntaxParser; | |
| 24 | |
| 25 class CFDE_XMLNode : public CFX_Target { | |
| 26 public: | |
| 27 CFDE_XMLNode(); | |
| 28 virtual void Release() { delete this; } | |
| 29 virtual FDE_XMLNODETYPE GetType() const { return FDE_XMLNODE_Unknown; } | |
| 30 virtual int32_t CountChildNodes() const; | |
| 31 virtual CFDE_XMLNode* GetChildNode(int32_t index) const; | |
| 32 virtual int32_t GetChildNodeIndex(CFDE_XMLNode* pNode) const; | |
| 33 virtual CFDE_XMLNode* GetPath(const FX_WCHAR* pPath, | |
| 34 int32_t iLength = -1, | |
| 35 FX_BOOL bQualifiedName = TRUE) const; | |
| 36 virtual int32_t InsertChildNode(CFDE_XMLNode* pNode, int32_t index = -1); | |
| 37 virtual void RemoveChildNode(CFDE_XMLNode* pNode); | |
| 38 virtual void DeleteChildren(); | |
| 39 virtual CFDE_XMLNode* GetNodeItem(IFDE_XMLNode::NodeItem eItem) const; | |
| 40 virtual int32_t GetNodeLevel() const; | |
| 41 virtual FX_BOOL InsertNodeItem(IFDE_XMLNode::NodeItem eItem, | |
| 42 CFDE_XMLNode* pNode); | |
| 43 virtual CFDE_XMLNode* RemoveNodeItem(IFDE_XMLNode::NodeItem eItem); | |
| 44 virtual CFDE_XMLNode* Clone(FX_BOOL bRecursive); | |
| 45 virtual void SaveXMLNode(IFX_Stream* pXMLStream); | |
| 46 | |
| 47 public: | |
| 48 ~CFDE_XMLNode(); | |
| 49 void CloneChildren(CFDE_XMLNode* pClone); | |
| 50 CFDE_XMLNode* m_pParent; | |
| 51 CFDE_XMLNode* m_pChild; | |
| 52 CFDE_XMLNode* m_pPrior; | |
| 53 CFDE_XMLNode* m_pNext; | |
| 54 }; | |
| 55 class CFDE_XMLInstruction : public CFDE_XMLNode { | |
| 56 public: | |
| 57 CFDE_XMLInstruction(const CFX_WideString& wsTarget); | |
| 58 virtual void Release() { delete this; } | |
| 59 virtual FDE_XMLNODETYPE GetType() const { return FDE_XMLNODE_Instruction; } | |
| 60 virtual CFDE_XMLNode* Clone(FX_BOOL bRecursive); | |
| 61 virtual void GetTargetName(CFX_WideString& wsTarget) const { | |
| 62 wsTarget = m_wsTarget; | |
| 63 } | |
| 64 virtual int32_t CountAttributes() const; | |
| 65 virtual FX_BOOL GetAttribute(int32_t index, | |
| 66 CFX_WideString& wsAttriName, | |
| 67 CFX_WideString& wsAttriValue) const; | |
| 68 virtual FX_BOOL HasAttribute(const FX_WCHAR* pwsAttriName) const; | |
| 69 virtual void GetString(const FX_WCHAR* pwsAttriName, | |
| 70 CFX_WideString& wsAttriValue, | |
| 71 const FX_WCHAR* pwsDefValue = NULL) const; | |
| 72 virtual void SetString(const CFX_WideString& wsAttriName, | |
| 73 const CFX_WideString& wsAttriValue); | |
| 74 virtual int32_t GetInteger(const FX_WCHAR* pwsAttriName, | |
| 75 int32_t iDefValue = 0) const; | |
| 76 virtual void SetInteger(const FX_WCHAR* pwsAttriName, int32_t iAttriValue); | |
| 77 virtual FX_FLOAT GetFloat(const FX_WCHAR* pwsAttriName, | |
| 78 FX_FLOAT fDefValue = 0) const; | |
| 79 virtual void SetFloat(const FX_WCHAR* pwsAttriName, FX_FLOAT fAttriValue); | |
| 80 virtual void RemoveAttribute(const FX_WCHAR* pwsAttriName); | |
| 81 virtual int32_t CountData() const; | |
| 82 virtual FX_BOOL GetData(int32_t index, CFX_WideString& wsData) const; | |
| 83 virtual void AppendData(const CFX_WideString& wsData); | |
| 84 virtual void RemoveData(int32_t index); | |
| 85 | |
| 86 public: | |
| 87 ~CFDE_XMLInstruction() {} | |
| 88 CFX_WideString m_wsTarget; | |
| 89 CFX_WideStringArray m_Attributes; | |
| 90 CFX_WideStringArray m_TargetData; | |
| 91 }; | |
| 92 class CFDE_XMLElement : public CFDE_XMLNode { | |
| 93 public: | |
| 94 CFDE_XMLElement(const CFX_WideString& wsTag); | |
| 95 virtual void Release() { delete this; } | |
| 96 virtual FDE_XMLNODETYPE GetType() const { return FDE_XMLNODE_Element; } | |
| 97 virtual CFDE_XMLNode* Clone(FX_BOOL bRecursive); | |
| 98 virtual void GetTagName(CFX_WideString& wsTag) const; | |
| 99 virtual void GetLocalTagName(CFX_WideString& wsTag) const; | |
| 100 virtual void GetNamespacePrefix(CFX_WideString& wsPrefix) const; | |
| 101 virtual void GetNamespaceURI(CFX_WideString& wsNamespace) const; | |
| 102 virtual int32_t CountAttributes() const; | |
| 103 virtual FX_BOOL GetAttribute(int32_t index, | |
| 104 CFX_WideString& wsAttriName, | |
| 105 CFX_WideString& wsAttriValue) const; | |
| 106 virtual FX_BOOL HasAttribute(const FX_WCHAR* pwsAttriName) const; | |
| 107 virtual void GetString(const FX_WCHAR* pwsAttriName, | |
| 108 CFX_WideString& wsAttriValue, | |
| 109 const FX_WCHAR* pwsDefValue = NULL) const; | |
| 110 virtual void SetString(const CFX_WideString& wsAttriName, | |
| 111 const CFX_WideString& wsAttriValue); | |
| 112 virtual int32_t GetInteger(const FX_WCHAR* pwsAttriName, | |
| 113 int32_t iDefValue = 0) const; | |
| 114 virtual void SetInteger(const FX_WCHAR* pwsAttriName, int32_t iAttriValue); | |
| 115 virtual FX_FLOAT GetFloat(const FX_WCHAR* pwsAttriName, | |
| 116 FX_FLOAT fDefValue = 0) const; | |
| 117 virtual void SetFloat(const FX_WCHAR* pwsAttriName, FX_FLOAT fAttriValue); | |
| 118 virtual void RemoveAttribute(const FX_WCHAR* pwsAttriName); | |
| 119 virtual void GetTextData(CFX_WideString& wsText) const; | |
| 120 virtual void SetTextData(const CFX_WideString& wsText); | |
| 121 | |
| 122 public: | |
| 123 ~CFDE_XMLElement(); | |
| 124 CFX_WideString m_wsTag; | |
| 125 CFX_WideStringArray m_Attributes; | |
| 126 }; | |
| 127 class CFDE_XMLText : public CFDE_XMLNode { | |
| 128 public: | |
| 129 CFDE_XMLText(const CFX_WideString& wsText); | |
| 130 virtual void Release() { delete this; } | |
| 131 virtual FDE_XMLNODETYPE GetType() const { return FDE_XMLNODE_Text; } | |
| 132 virtual CFDE_XMLNode* Clone(FX_BOOL bRecursive); | |
| 133 virtual void GetText(CFX_WideString& wsText) const { wsText = m_wsText; } | |
| 134 virtual void SetText(const CFX_WideString& wsText) { m_wsText = wsText; } | |
| 135 | |
| 136 public: | |
| 137 ~CFDE_XMLText() {} | |
| 138 CFX_WideString m_wsText; | |
| 139 }; | |
| 140 class CFDE_XMLDeclaration : public CFDE_XMLNode { | |
| 141 public: | |
| 142 CFDE_XMLDeclaration() : CFDE_XMLNode() {} | |
| 143 }; | |
| 144 class CFDE_XMLCharData : public CFDE_XMLDeclaration { | |
| 145 public: | |
| 146 CFDE_XMLCharData(const CFX_WideString& wsCData); | |
| 147 | |
| 148 virtual void Release() { delete this; } | |
| 149 virtual FDE_XMLNODETYPE GetType() const { return FDE_XMLNODE_CharData; } | |
| 150 virtual CFDE_XMLNode* Clone(FX_BOOL bRecursive); | |
| 151 virtual void GetCharData(CFX_WideString& wsCharData) const { | |
| 152 wsCharData = m_wsCharData; | |
| 153 } | |
| 154 virtual void SetCharData(const CFX_WideString& wsCData) { | |
| 155 m_wsCharData = wsCData; | |
| 156 } | |
| 157 | |
| 158 public: | |
| 159 ~CFDE_XMLCharData() {} | |
| 160 | |
| 161 CFX_WideString m_wsCharData; | |
| 162 }; | |
| 163 class CFDE_XMLDoc : public CFX_Target { | |
| 164 public: | |
| 165 CFDE_XMLDoc(); | |
| 166 ~CFDE_XMLDoc(); | |
| 167 virtual void Release() { delete this; } | |
| 168 virtual FX_BOOL LoadXML(IFX_Stream* pXMLStream, | |
| 169 int32_t iXMLPlaneSize = 8192, | |
| 170 int32_t iTextDataSize = 256, | |
| 171 FDE_XMLREADERHANDLER* pHandler = NULL); | |
| 172 virtual FX_BOOL LoadXML(IFDE_XMLParser* pXMLParser); | |
| 173 virtual int32_t DoLoad(IFX_Pause* pPause = NULL); | |
| 174 virtual void CloseXML(); | |
| 175 virtual CFDE_XMLNode* GetRoot() const { return m_pRoot; } | |
| 176 virtual void SaveXML(IFX_Stream* pXMLStream = NULL, FX_BOOL bSaveBOM = TRUE); | |
| 177 virtual void SaveXMLNode(IFX_Stream* pXMLStream, IFDE_XMLNode* pNode); | |
| 178 | |
| 179 protected: | |
| 180 IFX_Stream* m_pStream; | |
| 181 int32_t m_iStatus; | |
| 182 CFDE_XMLNode* m_pRoot; | |
| 183 IFDE_XMLSyntaxParser* m_pSyntaxParser; | |
| 184 IFDE_XMLParser* m_pXMLParser; | |
| 185 void Reset(FX_BOOL bInitRoot); | |
| 186 void ReleaseParser(); | |
| 187 }; | |
| 188 typedef CFX_StackTemplate<CFDE_XMLNode*> CFDE_XMLDOMNodeStack; | |
| 189 class CFDE_XMLDOMParser : public IFDE_XMLParser, public CFX_Target { | |
| 190 public: | |
| 191 CFDE_XMLDOMParser(CFDE_XMLNode* pRoot, IFDE_XMLSyntaxParser* pParser); | |
| 192 ~CFDE_XMLDOMParser(); | |
| 193 | |
| 194 virtual void Release() { delete this; } | |
| 195 virtual int32_t DoParser(IFX_Pause* pPause); | |
| 196 | |
| 197 private: | |
| 198 IFDE_XMLSyntaxParser* m_pParser; | |
| 199 CFDE_XMLNode* m_pParent; | |
| 200 CFDE_XMLNode* m_pChild; | |
| 201 CFDE_XMLDOMNodeStack m_NodeStack; | |
| 202 CFX_WideString m_ws1; | |
| 203 CFX_WideString m_ws2; | |
| 204 }; | |
| 205 class CFDE_XMLTAG : public CFX_Target { | |
| 206 public: | |
| 207 CFDE_XMLTAG() : eType(FDE_XMLNODE_Unknown) {} | |
| 208 CFDE_XMLTAG(const CFDE_XMLTAG& src) | |
| 209 : wsTagName(src.wsTagName), eType(src.eType) {} | |
| 210 CFX_WideString wsTagName; | |
| 211 FDE_XMLNODETYPE eType; | |
| 212 }; | |
| 213 typedef CFX_ObjectStackTemplate<CFDE_XMLTAG> CFDE_XMLTagStack; | |
| 214 class CFDE_XMLSAXParser : public IFDE_XMLParser, public CFX_Target { | |
| 215 public: | |
| 216 CFDE_XMLSAXParser(FDE_XMLREADERHANDLER* pHandler, | |
| 217 IFDE_XMLSyntaxParser* pParser); | |
| 218 ~CFDE_XMLSAXParser(); | |
| 219 | |
| 220 virtual void Release() { delete this; } | |
| 221 virtual int32_t DoParser(IFX_Pause* pPause); | |
| 222 | |
| 223 private: | |
| 224 void Push(const CFDE_XMLTAG& xmlTag); | |
| 225 void Pop(); | |
| 226 FDE_XMLREADERHANDLER* m_pHandler; | |
| 227 IFDE_XMLSyntaxParser* m_pParser; | |
| 228 CFDE_XMLTagStack m_TagStack; | |
| 229 CFDE_XMLTAG* m_pTagTop; | |
| 230 CFX_WideString m_ws1; | |
| 231 CFX_WideString m_ws2; | |
| 232 }; | |
| 233 | |
| 234 class CFDE_BlockBuffer : public CFX_Target { | |
| 235 public: | |
| 236 CFDE_BlockBuffer(int32_t iAllocStep = 1024 * 1024); | |
| 237 ~CFDE_BlockBuffer(); | |
| 238 | |
| 239 FX_BOOL InitBuffer(int32_t iBufferSize = 1024 * 1024); | |
| 240 FX_BOOL IsInitialized() { return m_iBufferSize / m_iAllocStep >= 1; } | |
| 241 void ReleaseBuffer() { delete this; } | |
| 242 FX_WCHAR* GetAvailableBlock(int32_t& iIndexInBlock); | |
| 243 inline int32_t GetAllocStep() const { return m_iAllocStep; } | |
| 244 inline int32_t& GetDataLengthRef() { return m_iDataLength; } | |
| 245 inline void Reset(FX_BOOL bReserveData = TRUE) { | |
| 246 if (!bReserveData) { | |
| 247 m_iStartPosition = 0; | |
| 248 } | |
| 249 m_iDataLength = 0; | |
| 250 } | |
| 251 void SetTextChar(int32_t iIndex, FX_WCHAR ch); | |
| 252 int32_t DeleteTextChars(int32_t iCount, FX_BOOL bDirection = TRUE); | |
| 253 void GetTextData(CFX_WideString& wsTextData, | |
| 254 int32_t iStart = 0, | |
| 255 int32_t iLength = -1) const; | |
| 256 | |
| 257 protected: | |
| 258 inline void TextDataIndex2BufIndex(const int32_t iIndex, | |
| 259 int32_t& iBlockIndex, | |
| 260 int32_t& iInnerIndex) const; | |
| 261 void ClearBuffer(); | |
| 262 CFX_PtrArray m_BlockArray; | |
| 263 int32_t m_iDataLength; | |
| 264 int32_t m_iBufferSize; | |
| 265 int32_t m_iAllocStep; | |
| 266 int32_t m_iStartPosition; | |
| 267 }; | |
| 268 | |
| 269 #define FDE_XMLSYNTAXMODE_Text 0 | |
| 270 #define FDE_XMLSYNTAXMODE_Node 1 | |
| 271 #define FDE_XMLSYNTAXMODE_Target 2 | |
| 272 #define FDE_XMLSYNTAXMODE_Tag 3 | |
| 273 #define FDE_XMLSYNTAXMODE_AttriName 4 | |
| 274 #define FDE_XMLSYNTAXMODE_AttriEqualSign 5 | |
| 275 #define FDE_XMLSYNTAXMODE_AttriQuotation 6 | |
| 276 #define FDE_XMLSYNTAXMODE_AttriValue 7 | |
| 277 #define FDE_XMLSYNTAXMODE_Entity 8 | |
| 278 #define FDE_XMLSYNTAXMODE_EntityDecimal 9 | |
| 279 #define FDE_XMLSYNTAXMODE_EntityHex 10 | |
| 280 #define FDE_XMLSYNTAXMODE_CloseInstruction 11 | |
| 281 #define FDE_XMLSYNTAXMODE_BreakElement 12 | |
| 282 #define FDE_XMLSYNTAXMODE_CloseElement 13 | |
| 283 #define FDE_XMLSYNTAXMODE_SkipDeclNode 14 | |
| 284 #define FDE_XMLSYNTAXMODE_DeclCharData 15 | |
| 285 #define FDE_XMLSYNTAXMODE_SkipComment 16 | |
| 286 #define FDE_XMLSYNTAXMODE_SkipCommentOrDecl 17 | |
| 287 #define FDE_XMLSYNTAXMODE_TargetData 18 | |
| 288 class CFDE_XMLSyntaxParser : public IFDE_XMLSyntaxParser, public CFX_Target { | |
| 289 public: | |
| 290 CFDE_XMLSyntaxParser(); | |
| 291 ~CFDE_XMLSyntaxParser(); | |
| 292 virtual void Release() { delete this; } | |
| 293 virtual void Init(IFX_Stream* pStream, | |
| 294 int32_t iXMLPlaneSize, | |
| 295 int32_t iTextDataSize = 256); | |
| 296 virtual FX_DWORD DoSyntaxParse(); | |
| 297 virtual int32_t GetStatus() const; | |
| 298 virtual int32_t GetCurrentPos() const { | |
| 299 return m_iParsedChars + (m_pStart - m_pBuffer); | |
| 300 } | |
| 301 virtual FX_FILESIZE GetCurrentBinaryPos() const; | |
| 302 virtual int32_t GetCurrentNodeNumber() const { return m_iCurrentNodeNum; } | |
| 303 virtual int32_t GetLastNodeNumber() const { return m_iLastNodeNum; } | |
| 304 | |
| 305 virtual void GetTargetName(CFX_WideString& wsTarget) const { | |
| 306 m_BlockBuffer.GetTextData(wsTarget, 0, m_iTextDataLength); | |
| 307 } | |
| 308 virtual void GetTagName(CFX_WideString& wsTag) const { | |
| 309 m_BlockBuffer.GetTextData(wsTag, 0, m_iTextDataLength); | |
| 310 } | |
| 311 virtual void GetAttributeName(CFX_WideString& wsAttriName) const { | |
| 312 m_BlockBuffer.GetTextData(wsAttriName, 0, m_iTextDataLength); | |
| 313 } | |
| 314 virtual void GetAttributeValue(CFX_WideString& wsAttriValue) const { | |
| 315 m_BlockBuffer.GetTextData(wsAttriValue, 0, m_iTextDataLength); | |
| 316 } | |
| 317 virtual void GetTextData(CFX_WideString& wsText) const { | |
| 318 m_BlockBuffer.GetTextData(wsText, 0, m_iTextDataLength); | |
| 319 } | |
| 320 virtual void GetTargetData(CFX_WideString& wsData) const { | |
| 321 m_BlockBuffer.GetTextData(wsData, 0, m_iTextDataLength); | |
| 322 } | |
| 323 | |
| 324 protected: | |
| 325 IFX_Stream* m_pStream; | |
| 326 int32_t m_iXMLPlaneSize; | |
| 327 int32_t m_iCurrentPos; | |
| 328 int32_t m_iCurrentNodeNum; | |
| 329 int32_t m_iLastNodeNum; | |
| 330 int32_t m_iParsedChars; | |
| 331 int32_t m_iParsedBytes; | |
| 332 FX_WCHAR* m_pBuffer; | |
| 333 int32_t m_iBufferChars; | |
| 334 FX_BOOL m_bEOS; | |
| 335 FX_WCHAR* m_pStart; | |
| 336 FX_WCHAR* m_pEnd; | |
| 337 FDE_XMLNODE m_CurNode; | |
| 338 CFDE_XMLNodeStack m_XMLNodeStack; | |
| 339 CFDE_BlockBuffer m_BlockBuffer; | |
| 340 int32_t m_iAllocStep; | |
| 341 int32_t& m_iDataLength; | |
| 342 FX_WCHAR* m_pCurrentBlock; | |
| 343 int32_t m_iIndexInBlock; | |
| 344 int32_t m_iTextDataLength; | |
| 345 FX_DWORD m_dwStatus; | |
| 346 FX_DWORD m_dwMode; | |
| 347 FX_WCHAR m_wQuotationMark; | |
| 348 int32_t m_iEntityStart; | |
| 349 CFX_DWordStack m_SkipStack; | |
| 350 FX_WCHAR m_SkipChar; | |
| 351 inline void ParseTextChar(FX_WCHAR ch); | |
| 352 }; | |
| 353 | |
| 354 #endif // XFA_SRC_FDE_XML_FDE_XML_IMP_H_ | |
| OLD | NEW |