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 _FX_SAX_
8 #define _FX_SAX_
9 class IFX_SAXReaderHandler;
10 class IFX_SAXReader;
11 #define FX_SAXPARSEMODE_NotConvert_amp 0x0001
12 #define FX_SAXPARSEMODE_NotConvert_lt 0x0002
13 #define FX_SAXPARSEMODE_NotConvert_gt 0x0004
14 #define FX_SAXPARSEMODE_NotConvert_apos 0x0008
15 #define FX_SAXPARSEMODE_NotConvert_quot 0x0010
16 #define FX_SAXPARSEMODE_NotConvert_sharp 0x0020
17 #define FX_SAXPARSEMODE_NotSkipSpace 0x0100
18 enum FX_SAXNODE {
19   FX_SAXNODE_Unknown = 0,
20   FX_SAXNODE_Instruction,
21   FX_SAXNODE_Declaration,
22   FX_SAXNODE_Comment,
23   FX_SAXNODE_Tag,
24   FX_SAXNODE_Text,
25   FX_SAXNODE_CharData,
26 };
27 class IFX_SAXReaderHandler {
28  public:
~IFX_SAXReaderHandler()29   virtual ~IFX_SAXReaderHandler() {}
30   virtual void* OnTagEnter(const CFX_ByteStringC& bsTagName,
31                            FX_SAXNODE eType,
32                            FX_DWORD dwStartPos) = 0;
33   virtual void OnTagAttribute(void* pTag,
34                               const CFX_ByteStringC& bsAttri,
35                               const CFX_ByteStringC& bsValue) = 0;
36   virtual void OnTagBreak(void* pTag) = 0;
37   virtual void OnTagData(void* pTag,
38                          FX_SAXNODE eType,
39                          const CFX_ByteStringC& bsData,
40                          FX_DWORD dwStartPos) = 0;
41   virtual void OnTagClose(void* pTag, FX_DWORD dwEndPos) = 0;
42   virtual void OnTagEnd(void* pTag,
43                         const CFX_ByteStringC& bsTagName,
44                         FX_DWORD dwEndPos) = 0;
45   virtual void OnTargetData(void* pTag,
46                             FX_SAXNODE eType,
47                             const CFX_ByteStringC& bsData,
48                             FX_DWORD dwStartPos) = 0;
49 };
50 class IFX_SAXReader {
51  public:
~IFX_SAXReader()52   virtual ~IFX_SAXReader() {}
53   virtual void Release() = 0;
54   virtual int32_t StartParse(IFX_FileRead* pFile,
55                              FX_DWORD dwStart = 0,
56                              FX_DWORD dwLen = -1,
57                              FX_DWORD dwParseMode = 0) = 0;
58   virtual int32_t ContinueParse(IFX_Pause* pPause = NULL) = 0;
59   virtual void SkipCurrentNode() = 0;
60   virtual void SetHandler(IFX_SAXReaderHandler* pHandler) = 0;
61 };
62 IFX_SAXReader* FX_SAXReader_Create();
63 #endif
64