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_FGAS_XML_FGAS_SAX_IMP_H_ | |
8 #define XFA_SRC_FGAS_XML_FGAS_SAX_IMP_H_ | |
9 | |
10 #include "xfa/src/fgas/xml/fgas_sax.h" | |
11 | |
12 class CFX_SAXFile { | |
13 public: | |
14 CFX_SAXFile(); | |
15 FX_BOOL StartFile(IFX_FileRead* pFile, FX_DWORD dwStart, FX_DWORD dwLen); | |
16 FX_BOOL ReadNextBlock(); | |
17 void Reset(); | |
18 IFX_FileRead* m_pFile; | |
19 FX_DWORD m_dwStart; | |
20 FX_DWORD m_dwEnd; | |
21 FX_DWORD m_dwCur; | |
22 uint8_t* m_pBuf; | |
23 FX_DWORD m_dwBufSize; | |
24 FX_DWORD m_dwBufIndex; | |
25 }; | |
26 | |
27 enum FX_SAXMODE { | |
28 FX_SAXMODE_Text = 0, | |
29 FX_SAXMODE_NodeStart, | |
30 FX_SAXMODE_DeclOrComment, | |
31 FX_SAXMODE_DeclNode, | |
32 FX_SAXMODE_Comment, | |
33 FX_SAXMODE_CommentContent, | |
34 FX_SAXMODE_TagName, | |
35 FX_SAXMODE_TagAttributeName, | |
36 FX_SAXMODE_TagAttributeEqual, | |
37 FX_SAXMODE_TagAttributeValue, | |
38 FX_SAXMODE_TagMaybeClose, | |
39 FX_SAXMODE_TagClose, | |
40 FX_SAXMODE_TagEnd, | |
41 FX_SAXMODE_TargetData, | |
42 FX_SAXMODE_MAX, | |
43 }; | |
44 | |
45 class CFX_SAXItem { | |
46 public: | |
47 CFX_SAXItem() | |
48 : m_pNode(NULL), | |
49 m_eNode(FX_SAXNODE_Unknown), | |
50 m_dwID(0), | |
51 m_bSkip(FALSE), | |
52 m_pPrev(NULL), | |
53 m_pNext(NULL) {} | |
54 void* m_pNode; | |
55 FX_SAXNODE m_eNode; | |
56 FX_DWORD m_dwID; | |
57 FX_BOOL m_bSkip; | |
58 CFX_SAXItem* m_pPrev; | |
59 CFX_SAXItem* m_pNext; | |
60 }; | |
61 | |
62 class CFX_SAXCommentContext { | |
63 public: | |
64 CFX_SAXCommentContext() : m_iHeaderCount(0), m_iTailCount(0) {} | |
65 int32_t m_iHeaderCount; | |
66 int32_t m_iTailCount; | |
67 }; | |
68 | |
69 class CFX_SAXReader : public IFX_SAXReader { | |
70 public: | |
71 CFX_SAXReader(); | |
72 ~CFX_SAXReader(); | |
73 virtual void Release() { delete this; } | |
74 virtual int32_t StartParse(IFX_FileRead* pFile, | |
75 FX_DWORD dwStart = 0, | |
76 FX_DWORD dwLen = -1, | |
77 FX_DWORD dwParseMode = 0); | |
78 virtual int32_t ContinueParse(IFX_Pause* pPause = NULL); | |
79 virtual void SkipCurrentNode(); | |
80 virtual void SetHandler(IFX_SAXReaderHandler* pHandler); | |
81 void AppendData(uint8_t ch); | |
82 void AppendName(uint8_t ch); | |
83 void ParseText(); | |
84 void ParseNodeStart(); | |
85 void ParseInstruction(); | |
86 void ParseDeclOrComment(); | |
87 void ParseDeclNode(); | |
88 void ParseComment(); | |
89 void ParseCommentContent(); | |
90 void ParseTagName(); | |
91 void ParseTagAttributeName(); | |
92 void ParseTagAttributeEqual(); | |
93 void ParseTagAttributeValue(); | |
94 void ParseMaybeClose(); | |
95 void ParseTagClose(); | |
96 void ParseTagEnd(); | |
97 void ParseTargetData(); | |
98 | |
99 protected: | |
100 CFX_SAXFile m_File; | |
101 IFX_SAXReaderHandler* m_pHandler; | |
102 int32_t m_iState; | |
103 CFX_SAXItem* m_pRoot; | |
104 CFX_SAXItem* m_pCurItem; | |
105 FX_DWORD m_dwItemID; | |
106 FX_SAXMODE m_eMode; | |
107 FX_SAXMODE m_ePrevMode; | |
108 FX_BOOL m_bCharData; | |
109 uint8_t m_CurByte; | |
110 FX_DWORD m_dwDataOffset; | |
111 CFX_ByteArray m_SkipStack; | |
112 uint8_t m_SkipChar; | |
113 FX_DWORD m_dwNodePos; | |
114 uint8_t* m_pszData; | |
115 int32_t m_iDataSize; | |
116 int32_t m_iDataLength; | |
117 int32_t m_iEntityStart; | |
118 int32_t m_iDataPos; | |
119 uint8_t* m_pszName; | |
120 int32_t m_iNameSize; | |
121 int32_t m_iNameLength; | |
122 FX_DWORD m_dwParseMode; | |
123 CFX_SAXCommentContext* m_pCommentContext; | |
124 void Reset(); | |
125 void Push(); | |
126 void Pop(); | |
127 FX_BOOL SkipSpace(uint8_t ch); | |
128 void SkipNode(); | |
129 void NotifyData(); | |
130 void NotifyEnter(); | |
131 void NotifyAttribute(); | |
132 void NotifyBreak(); | |
133 void NotifyClose(); | |
134 void NotifyEnd(); | |
135 void NotifyTargetData(); | |
136 void ReallocDataBuffer(); | |
137 void ReallocNameBuffer(); | |
138 void ParseChar(uint8_t ch); | |
139 }; | |
140 | |
141 #endif // XFA_SRC_FGAS_XML_FGAS_SAX_IMP_H_ | |
OLD | NEW |