OLD | NEW |
1 // Copyright 2014 PDFium Authors. All rights reserved. | 1 // Copyright 2014 PDFium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
6 | 6 |
7 #ifndef CORE_INCLUDE_FXCRT_FX_XML_H_ | 7 #ifndef CORE_INCLUDE_FXCRT_FX_XML_H_ |
8 #define CORE_INCLUDE_FXCRT_FX_XML_H_ | 8 #define CORE_INCLUDE_FXCRT_FX_XML_H_ |
9 | 9 |
10 #include "fx_basic.h" | 10 #include <vector> |
| 11 |
| 12 #include "core/include/fxcrt/fx_basic.h" |
11 | 13 |
12 class CXML_AttrItem { | 14 class CXML_AttrItem { |
13 public: | 15 public: |
14 CFX_ByteString m_QSpaceName; | 16 CFX_ByteString m_QSpaceName; |
15 CFX_ByteString m_AttrName; | 17 CFX_ByteString m_AttrName; |
16 CFX_WideString m_Value; | 18 CFX_WideString m_Value; |
17 }; | 19 }; |
| 20 |
18 class CXML_AttrMap { | 21 class CXML_AttrMap { |
19 public: | 22 public: |
20 CXML_AttrMap() { m_pMap = NULL; } | 23 CXML_AttrMap() { m_pMap = NULL; } |
21 ~CXML_AttrMap() { RemoveAll(); } | 24 ~CXML_AttrMap() { RemoveAll(); } |
22 const CFX_WideString* Lookup(const CFX_ByteStringC& space, | 25 const CFX_WideString* Lookup(const CFX_ByteStringC& space, |
23 const CFX_ByteStringC& name) const; | 26 const CFX_ByteStringC& name) const; |
24 void SetAt(const CFX_ByteStringC& space, | 27 void SetAt(const CFX_ByteStringC& space, |
25 const CFX_ByteStringC& name, | 28 const CFX_ByteStringC& name, |
26 const CFX_WideStringC& value); | 29 const CFX_WideStringC& value); |
27 void RemoveAt(const CFX_ByteStringC& space, const CFX_ByteStringC& name); | 30 void RemoveAt(const CFX_ByteStringC& space, const CFX_ByteStringC& name); |
28 void RemoveAll(); | 31 void RemoveAll(); |
29 int GetSize() const; | 32 int GetSize() const; |
30 CXML_AttrItem& GetAt(int index) const; | 33 CXML_AttrItem& GetAt(int index) const; |
31 CFX_ObjectArray<CXML_AttrItem>* m_pMap; | 34 CFX_ObjectArray<CXML_AttrItem>* m_pMap; |
32 }; | 35 }; |
| 36 |
33 class CXML_Content { | 37 class CXML_Content { |
34 public: | 38 public: |
35 CXML_Content() : m_bCDATA(FALSE), m_Content() {} | 39 CXML_Content() : m_bCDATA(FALSE), m_Content() {} |
36 void Set(FX_BOOL bCDATA, const CFX_WideStringC& content) { | 40 void Set(FX_BOOL bCDATA, const CFX_WideStringC& content) { |
37 m_bCDATA = bCDATA; | 41 m_bCDATA = bCDATA; |
38 m_Content = content; | 42 m_Content = content; |
39 } | 43 } |
40 FX_BOOL m_bCDATA; | 44 FX_BOOL m_bCDATA; |
41 CFX_WideString m_Content; | 45 CFX_WideString m_Content; |
42 }; | 46 }; |
| 47 |
43 class CXML_Element { | 48 class CXML_Element { |
44 public: | 49 public: |
| 50 enum ChildType { Invalid, Element, Content }; |
| 51 |
45 static CXML_Element* Parse(const void* pBuffer, | 52 static CXML_Element* Parse(const void* pBuffer, |
46 size_t size, | 53 size_t size, |
47 FX_BOOL bSaveSpaceChars = FALSE, | 54 FX_BOOL bSaveSpaceChars = FALSE, |
48 FX_FILESIZE* pParsedSize = NULL); | 55 FX_FILESIZE* pParsedSize = NULL); |
49 static CXML_Element* Parse(IFX_FileRead* pFile, | 56 static CXML_Element* Parse(IFX_FileRead* pFile, |
50 FX_BOOL bSaveSpaceChars = FALSE, | 57 FX_BOOL bSaveSpaceChars = FALSE, |
51 FX_FILESIZE* pParsedSize = NULL); | 58 FX_FILESIZE* pParsedSize = NULL); |
52 static CXML_Element* Parse(IFX_BufferRead* pBuffer, | 59 static CXML_Element* Parse(IFX_BufferRead* pBuffer, |
53 FX_BOOL bSaveSpaceChars = FALSE, | 60 FX_BOOL bSaveSpaceChars = FALSE, |
54 FX_FILESIZE* pParsedSize = NULL); | 61 FX_FILESIZE* pParsedSize = NULL); |
| 62 |
55 CXML_Element(const CFX_ByteStringC& qSpace, const CFX_ByteStringC& tagName); | 63 CXML_Element(const CFX_ByteStringC& qSpace, const CFX_ByteStringC& tagName); |
56 CXML_Element(const CFX_ByteStringC& qTagName); | 64 CXML_Element(const CFX_ByteStringC& qTagName); |
57 CXML_Element(); | 65 CXML_Element(); |
58 | |
59 ~CXML_Element(); | 66 ~CXML_Element(); |
60 | 67 |
61 void Empty(); | 68 void Empty(); |
62 | |
63 CFX_ByteString GetTagName(FX_BOOL bQualified = FALSE) const; | 69 CFX_ByteString GetTagName(FX_BOOL bQualified = FALSE) const; |
64 | |
65 CFX_ByteString GetNamespace(FX_BOOL bQualified = FALSE) const; | 70 CFX_ByteString GetNamespace(FX_BOOL bQualified = FALSE) const; |
66 | |
67 CFX_ByteString GetNamespaceURI(const CFX_ByteStringC& qName) const; | 71 CFX_ByteString GetNamespaceURI(const CFX_ByteStringC& qName) const; |
68 | |
69 CXML_Element* GetParent() const { return m_pParent; } | 72 CXML_Element* GetParent() const { return m_pParent; } |
70 | |
71 FX_DWORD CountAttrs() const { return m_AttrMap.GetSize(); } | 73 FX_DWORD CountAttrs() const { return m_AttrMap.GetSize(); } |
72 | |
73 void GetAttrByIndex(int index, | 74 void GetAttrByIndex(int index, |
74 CFX_ByteString& space, | 75 CFX_ByteString& space, |
75 CFX_ByteString& name, | 76 CFX_ByteString& name, |
76 CFX_WideString& value) const; | 77 CFX_WideString& value) const; |
77 | |
78 FX_BOOL HasAttr(const CFX_ByteStringC& qName) const; | 78 FX_BOOL HasAttr(const CFX_ByteStringC& qName) const; |
79 | |
80 FX_BOOL GetAttrValue(const CFX_ByteStringC& name, | 79 FX_BOOL GetAttrValue(const CFX_ByteStringC& name, |
81 CFX_WideString& attribute) const; | 80 CFX_WideString& attribute) const; |
82 CFX_WideString GetAttrValue(const CFX_ByteStringC& name) const { | 81 CFX_WideString GetAttrValue(const CFX_ByteStringC& name) const { |
83 CFX_WideString attr; | 82 CFX_WideString attr; |
84 GetAttrValue(name, attr); | 83 GetAttrValue(name, attr); |
85 return attr; | 84 return attr; |
86 } | 85 } |
87 | 86 |
88 FX_BOOL GetAttrValue(const CFX_ByteStringC& space, | 87 FX_BOOL GetAttrValue(const CFX_ByteStringC& space, |
89 const CFX_ByteStringC& name, | 88 const CFX_ByteStringC& name, |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
122 FX_BOOL GetAttrFloat(const CFX_ByteStringC& space, | 121 FX_BOOL GetAttrFloat(const CFX_ByteStringC& space, |
123 const CFX_ByteStringC& name, | 122 const CFX_ByteStringC& name, |
124 FX_FLOAT& attribute) const; | 123 FX_FLOAT& attribute) const; |
125 FX_FLOAT GetAttrFloat(const CFX_ByteStringC& space, | 124 FX_FLOAT GetAttrFloat(const CFX_ByteStringC& space, |
126 const CFX_ByteStringC& name) const { | 125 const CFX_ByteStringC& name) const { |
127 FX_FLOAT attr = 0; | 126 FX_FLOAT attr = 0; |
128 GetAttrFloat(space, name, attr); | 127 GetAttrFloat(space, name, attr); |
129 return attr; | 128 return attr; |
130 } | 129 } |
131 | 130 |
132 FX_DWORD CountChildren() const; | 131 FX_DWORD CountChildren() const { return m_Children.size(); } |
133 | |
134 enum ChildType { Invalid, Element, Content }; | |
135 | |
136 ChildType GetChildType(FX_DWORD index) const; | 132 ChildType GetChildType(FX_DWORD index) const; |
137 | |
138 CFX_WideString GetContent(FX_DWORD index) const; | 133 CFX_WideString GetContent(FX_DWORD index) const; |
139 | |
140 CXML_Element* GetElement(FX_DWORD index) const; | 134 CXML_Element* GetElement(FX_DWORD index) const; |
141 | |
142 CXML_Element* GetElement(const CFX_ByteStringC& space, | 135 CXML_Element* GetElement(const CFX_ByteStringC& space, |
143 const CFX_ByteStringC& tag) const { | 136 const CFX_ByteStringC& tag) const { |
144 return GetElement(space, tag, 0); | 137 return GetElement(space, tag, 0); |
145 } | 138 } |
146 | 139 |
147 FX_DWORD CountElements(const CFX_ByteStringC& space, | 140 FX_DWORD CountElements(const CFX_ByteStringC& space, |
148 const CFX_ByteStringC& tag) const; | 141 const CFX_ByteStringC& tag) const; |
149 | |
150 CXML_Element* GetElement(const CFX_ByteStringC& space, | 142 CXML_Element* GetElement(const CFX_ByteStringC& space, |
151 const CFX_ByteStringC& tag, | 143 const CFX_ByteStringC& tag, |
152 int index) const; | 144 int index) const; |
153 | 145 |
154 FX_DWORD FindElement(CXML_Element* pChild) const; | 146 FX_DWORD FindElement(CXML_Element* pChild) const; |
155 | |
156 void SetTag(const CFX_ByteStringC& qSpace, const CFX_ByteStringC& tagname); | 147 void SetTag(const CFX_ByteStringC& qSpace, const CFX_ByteStringC& tagname); |
157 | |
158 void SetTag(const CFX_ByteStringC& qTagName); | 148 void SetTag(const CFX_ByteStringC& qTagName); |
159 | |
160 void RemoveChildren(); | 149 void RemoveChildren(); |
161 | |
162 void RemoveChild(FX_DWORD index); | 150 void RemoveChild(FX_DWORD index); |
163 | 151 |
164 protected: | 152 protected: |
| 153 struct ChildRecord { |
| 154 ChildType type; |
| 155 void* child; // CXML_Element and CXML_Content lack a common ancestor. |
| 156 }; |
| 157 |
165 CXML_Element* m_pParent; | 158 CXML_Element* m_pParent; |
166 CFX_ByteString m_QSpaceName; | 159 CFX_ByteString m_QSpaceName; |
167 CFX_ByteString m_TagName; | 160 CFX_ByteString m_TagName; |
| 161 CXML_AttrMap m_AttrMap; |
| 162 std::vector<ChildRecord> m_Children; |
168 | 163 |
169 CXML_AttrMap m_AttrMap; | |
170 | |
171 CFX_PtrArray m_Children; | |
172 friend class CXML_Parser; | 164 friend class CXML_Parser; |
173 friend class CXML_Composer; | 165 friend class CXML_Composer; |
174 }; | 166 }; |
175 | 167 |
176 #endif // CORE_INCLUDE_FXCRT_FX_XML_H_ | 168 #endif // CORE_INCLUDE_FXCRT_FX_XML_H_ |
OLD | NEW |