summaryrefslogtreecommitdiff
path: root/xfa/fgas/xml/fgas_sax.h
blob: 57ff6b2470a65cbc9838d14f72fdef0f3c65d41b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
// Copyright 2014 PDFium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com

#ifndef XFA_FGAS_XML_FGAS_SAX_H_
#define XFA_FGAS_XML_FGAS_SAX_H_

#include "core/fxcrt/include/fx_basic.h"

#define FX_SAXPARSEMODE_NotConvert_amp 0x0001
#define FX_SAXPARSEMODE_NotConvert_lt 0x0002
#define FX_SAXPARSEMODE_NotConvert_gt 0x0004
#define FX_SAXPARSEMODE_NotConvert_apos 0x0008
#define FX_SAXPARSEMODE_NotConvert_quot 0x0010
#define FX_SAXPARSEMODE_NotConvert_sharp 0x0020
#define FX_SAXPARSEMODE_NotSkipSpace 0x0100

enum FX_SAXNODE {
  FX_SAXNODE_Unknown = 0,
  FX_SAXNODE_Instruction,
  FX_SAXNODE_Declaration,
  FX_SAXNODE_Comment,
  FX_SAXNODE_Tag,
  FX_SAXNODE_Text,
  FX_SAXNODE_CharData,
};

enum FX_SAXMODE {
  FX_SAXMODE_Text = 0,
  FX_SAXMODE_NodeStart,
  FX_SAXMODE_DeclOrComment,
  FX_SAXMODE_DeclNode,
  FX_SAXMODE_Comment,
  FX_SAXMODE_CommentContent,
  FX_SAXMODE_TagName,
  FX_SAXMODE_TagAttributeName,
  FX_SAXMODE_TagAttributeEqual,
  FX_SAXMODE_TagAttributeValue,
  FX_SAXMODE_TagMaybeClose,
  FX_SAXMODE_TagClose,
  FX_SAXMODE_TagEnd,
  FX_SAXMODE_TargetData,
  FX_SAXMODE_MAX,
};

class CXFA_SAXReaderHandler;

class CFX_SAXFile {
 public:
  CFX_SAXFile();
  FX_BOOL StartFile(IFX_FileRead* pFile, uint32_t dwStart, uint32_t dwLen);
  FX_BOOL ReadNextBlock();
  void Reset();
  IFX_FileRead* m_pFile;
  uint32_t m_dwStart;
  uint32_t m_dwEnd;
  uint32_t m_dwCur;
  uint8_t* m_pBuf;
  uint32_t m_dwBufSize;
  uint32_t m_dwBufIndex;
};

class CFX_SAXItem {
 public:
  CFX_SAXItem()
      : m_pNode(NULL),
        m_eNode(FX_SAXNODE_Unknown),
        m_dwID(0),
        m_bSkip(FALSE),
        m_pPrev(NULL),
        m_pNext(NULL) {}
  void* m_pNode;
  FX_SAXNODE m_eNode;
  uint32_t m_dwID;
  FX_BOOL m_bSkip;
  CFX_SAXItem* m_pPrev;
  CFX_SAXItem* m_pNext;
};

class CFX_SAXCommentContext {
 public:
  CFX_SAXCommentContext() : m_iHeaderCount(0), m_iTailCount(0) {}
  int32_t m_iHeaderCount;
  int32_t m_iTailCount;
};

class CFX_SAXReader {
 public:
  CFX_SAXReader();
  ~CFX_SAXReader();

  void Release() { delete this; }
  int32_t StartParse(IFX_FileRead* pFile,
                     uint32_t dwStart = 0,
                     uint32_t dwLen = -1,
                     uint32_t dwParseMode = 0);
  int32_t ContinueParse(IFX_Pause* pPause = NULL);
  void SkipCurrentNode();
  void SetHandler(CXFA_SAXReaderHandler* pHandler);
  void AppendData(uint8_t ch);
  void AppendName(uint8_t ch);
  void ParseText();
  void ParseNodeStart();
  void ParseInstruction();
  void ParseDeclOrComment();
  void ParseDeclNode();
  void ParseComment();
  void ParseCommentContent();
  void ParseTagName();
  void ParseTagAttributeName();
  void ParseTagAttributeEqual();
  void ParseTagAttributeValue();
  void ParseMaybeClose();
  void ParseTagClose();
  void ParseTagEnd();
  void ParseTargetData();

 protected:
  void Reset();
  void Push();
  void Pop();
  FX_BOOL SkipSpace(uint8_t ch);
  void SkipNode();
  void NotifyData();
  void NotifyEnter();
  void NotifyAttribute();
  void NotifyBreak();
  void NotifyClose();
  void NotifyEnd();
  void NotifyTargetData();
  void ReallocDataBuffer();
  void ReallocNameBuffer();
  void ParseChar(uint8_t ch);

  CFX_SAXFile m_File;
  CXFA_SAXReaderHandler* m_pHandler;
  int32_t m_iState;
  CFX_SAXItem* m_pRoot;
  CFX_SAXItem* m_pCurItem;
  uint32_t m_dwItemID;
  FX_SAXMODE m_eMode;
  FX_SAXMODE m_ePrevMode;
  FX_BOOL m_bCharData;
  uint8_t m_CurByte;
  uint32_t m_dwDataOffset;
  CFX_ByteArray m_SkipStack;
  uint8_t m_SkipChar;
  uint32_t m_dwNodePos;
  uint8_t* m_pszData;
  int32_t m_iDataSize;
  int32_t m_iDataLength;
  int32_t m_iEntityStart;
  int32_t m_iDataPos;
  uint8_t* m_pszName;
  int32_t m_iNameSize;
  int32_t m_iNameLength;
  uint32_t m_dwParseMode;
  CFX_SAXCommentContext* m_pCommentContext;
};

#endif  // XFA_FGAS_XML_FGAS_SAX_H_