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