| 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 _FX_XML_H_ | 7 #ifndef _FX_XML_H_ |
| 8 #define _FX_XML_H_ | 8 #define _FX_XML_H_ |
| 9 #ifndef _FX_BASIC_H_ | 9 #ifndef _FX_BASIC_H_ |
| 10 #include "fx_basic.h" | 10 #include "fx_basic.h" |
| 11 #endif | 11 #endif |
| 12 class CXML_AttrItem : public CFX_Object | 12 class CXML_AttrItem : public CFX_Object |
| 13 { | 13 { |
| 14 public: | 14 public: |
| 15 CFX_ByteStringL» m_QSpaceName; | 15 CFX_ByteString» m_QSpaceName; |
| 16 CFX_ByteStringL» m_AttrName; | 16 CFX_ByteString» m_AttrName; |
| 17 CFX_WideStringL» m_Value; | 17 CFX_WideString» m_Value; |
| 18 | |
| 19 void» Empty(IFX_Allocator* pAllocator = NULL) | |
| 20 { | |
| 21 m_QSpaceName.Empty(pAllocator); | |
| 22 m_AttrName.Empty(pAllocator); | |
| 23 m_Value.Empty(pAllocator); | |
| 24 } | |
| 25 }; | 18 }; |
| 26 class CXML_AttrMap : public CFX_Object | 19 class CXML_AttrMap : public CFX_Object |
| 27 { | 20 { |
| 28 public: | 21 public: |
| 29 CXML_AttrMap() | 22 CXML_AttrMap() |
| 30 { | 23 { |
| 31 m_pMap = NULL; | 24 m_pMap = NULL; |
| 32 } | 25 } |
| 33 ~CXML_AttrMap() | 26 ~CXML_AttrMap() |
| 34 { | 27 { |
| 35 RemoveAll(NULL); | 28 RemoveAll(); |
| 36 } | 29 } |
| 37 const CFX_WideStringL*» Lookup(FX_BSTR space, FX_BSTR name) const; | 30 const CFX_WideString*» Lookup(FX_BSTR space, FX_BSTR name) const; |
| 38 void» » » » » SetAt(FX_BSTR space, FX_BSTR nam
e, FX_WSTR value, IFX_Allocator* pAllocator = NULL); | 31 void» » » » » SetAt(FX_BSTR space, FX_BSTR nam
e, FX_WSTR value); |
| 39 void» » » » » RemoveAt(FX_BSTR space, FX_BSTR
name, IFX_Allocator* pAllocator = NULL); | 32 void» » » » » RemoveAt(FX_BSTR space, FX_BSTR
name); |
| 40 void» » » » » RemoveAll(IFX_Allocator* pAlloca
tor = NULL); | 33 void» » » » » RemoveAll(); |
| 41 int GetSize() const; | 34 int GetSize() const; |
| 42 CXML_AttrItem& GetAt(int index) const; | 35 CXML_AttrItem& GetAt(int index) const; |
| 43 CFX_ObjectArray<CXML_AttrItem>* m_pMap; | 36 CFX_ObjectArray<CXML_AttrItem>* m_pMap; |
| 44 }; | 37 }; |
| 45 class CXML_Content : public CFX_Object | 38 class CXML_Content : public CFX_Object |
| 46 { | 39 { |
| 47 public: | 40 public: |
| 48 CXML_Content() : m_bCDATA(FALSE), m_Content() {} | 41 CXML_Content() : m_bCDATA(FALSE), m_Content() {} |
| 49 ~CXML_Content() | 42 void» Set(FX_BOOL bCDATA, FX_WSTR content) |
| 50 { | |
| 51 Empty(NULL); | |
| 52 } | |
| 53 void» Empty(IFX_Allocator* pAllocator = NULL) | |
| 54 { | |
| 55 m_Content.Empty(pAllocator); | |
| 56 } | |
| 57 void» Set(FX_BOOL bCDATA, FX_WSTR content, IFX_Allocator* pAllocator =
NULL) | |
| 58 { | 43 { |
| 59 m_bCDATA = bCDATA; | 44 m_bCDATA = bCDATA; |
| 60 m_Content.Set(content, pAllocator); | 45 m_Content = content; |
| 61 } | 46 } |
| 62 FX_BOOL m_bCDATA; | 47 FX_BOOL m_bCDATA; |
| 63 CFX_WideStringL» m_Content; | 48 CFX_WideString» m_Content; |
| 64 }; | 49 }; |
| 65 class CXML_Element : public CFX_Object | 50 class CXML_Element : public CFX_Object |
| 66 { | 51 { |
| 67 public: | 52 public: |
| 68 | 53 static CXML_Element*» Parse(const void* pBuffer, size_t size, FX_BOOL
bSaveSpaceChars = FALSE, FX_FILESIZE* pParsedSize = NULL); |
| 69 static CXML_Element*» Parse(const void* pBuffer, size_t size, FX_BOOL
bSaveSpaceChars = FALSE, FX_FILESIZE* pParsedSize = NULL, IFX_Allocator* pAlloca
tor = NULL); | 54 static CXML_Element*» Parse(IFX_FileRead *pFile, FX_BOOL bSaveSpaceCha
rs = FALSE, FX_FILESIZE* pParsedSize = NULL); |
| 70 | 55 static CXML_Element*» Parse(IFX_BufferRead *pBuffer, FX_BOOL bSaveSpac
eChars = FALSE, FX_FILESIZE* pParsedSize = NULL); |
| 71 static CXML_Element*» Parse(IFX_FileRead *pFile, FX_BOOL bSaveSpaceCha
rs = FALSE, FX_FILESIZE* pParsedSize = NULL, IFX_Allocator* pAllocator = NULL); | 56 CXML_Element(FX_BSTR qSpace, FX_BSTR tagName); |
| 72 | 57 CXML_Element(FX_BSTR qTagName); |
| 73 static CXML_Element*» Parse(IFX_BufferRead *pBuffer, FX_BOOL bSaveSpac
eChars = FALSE, FX_FILESIZE* pParsedSize = NULL, IFX_Allocator* pAllocator = NUL
L); | 58 CXML_Element(); |
| 74 | |
| 75 CXML_Element(FX_BSTR qSpace, FX_BSTR tagName, IFX_Allocator* pAllocator = NU
LL); | |
| 76 | |
| 77 CXML_Element(FX_BSTR qTagName, IFX_Allocator* pAllocator = NULL); | |
| 78 | |
| 79 CXML_Element(IFX_Allocator* pAllocator = NULL); | |
| 80 | 59 |
| 81 ~CXML_Element(); | 60 ~CXML_Element(); |
| 82 | 61 |
| 83 void Empty(); | 62 void Empty(); |
| 84 | 63 |
| 85 | 64 |
| 86 | 65 |
| 87 CFX_ByteString GetTagName(FX_BOOL bQualified = FALSE) c
onst; | 66 CFX_ByteString GetTagName(FX_BOOL bQualified = FALSE) c
onst; |
| 88 void GetTagName(CFX_ByteStringL &tagN
ame, FX_BOOL bQualified = FALSE) const; | |
| 89 | 67 |
| 90 CFX_ByteString GetNamespace(FX_BOOL bQualified = FALSE)
const; | 68 CFX_ByteString GetNamespace(FX_BOOL bQualified = FALSE)
const; |
| 91 void GetNamespace(CFX_ByteStringL &na
meSpace, FX_BOOL bQualified = FALSE) const; | |
| 92 | 69 |
| 93 CFX_ByteString GetNamespaceURI(FX_BSTR qName) const; | 70 CFX_ByteString GetNamespaceURI(FX_BSTR qName) const; |
| 94 void GetNamespaceURI(FX_BSTR qName, C
FX_ByteStringL &uri) const; | |
| 95 | 71 |
| 96 CXML_Element* GetParent() const | 72 CXML_Element* GetParent() const |
| 97 { | 73 { |
| 98 return m_pParent; | 74 return m_pParent; |
| 99 } | 75 } |
| 100 | 76 |
| 101 FX_DWORD CountAttrs() const | 77 FX_DWORD CountAttrs() const |
| 102 { | 78 { |
| 103 return m_AttrMap.GetSize(); | 79 return m_AttrMap.GetSize(); |
| 104 } | 80 } |
| 105 | 81 |
| 106 void GetAttrByIndex(int index, CFX_By
teString &space, CFX_ByteString &name, CFX_WideString &value) const; | 82 void GetAttrByIndex(int index, CFX_By
teString &space, CFX_ByteString &name, CFX_WideString &value) const; |
| 107 void GetAttrByIndex(int index, CFX_By
teStringL &space, CFX_ByteStringL &name, CFX_WideStringL &value) const; | |
| 108 | 83 |
| 109 FX_BOOL HasAttr(FX_BSTR qName) const; | 84 FX_BOOL HasAttr(FX_BSTR qName) const; |
| 110 | 85 |
| 111 FX_BOOL GetAttrValue(FX_BSTR name, CFX_W
ideString& attribute) const; | 86 FX_BOOL GetAttrValue(FX_BSTR name, CFX_W
ideString& attribute) const; |
| 112 CFX_WideString GetAttrValue(FX_BSTR name) const | 87 CFX_WideString GetAttrValue(FX_BSTR name) const |
| 113 { | 88 { |
| 114 CFX_WideString attr; | 89 CFX_WideString attr; |
| 115 GetAttrValue(name, attr); | 90 GetAttrValue(name, attr); |
| 116 return attr; | 91 return attr; |
| 117 } | 92 } |
| 118 const CFX_WideStringL* GetAttrValuePtr(FX_BSTR name) const; | |
| 119 | 93 |
| 120 FX_BOOL GetAttrValue(FX_BSTR space, FX_B
STR name, CFX_WideString& attribute) const; | 94 FX_BOOL GetAttrValue(FX_BSTR space, FX_B
STR name, CFX_WideString& attribute) const; |
| 121 CFX_WideString GetAttrValue(FX_BSTR space, FX_BSTR name
) const | 95 CFX_WideString GetAttrValue(FX_BSTR space, FX_BSTR name
) const |
| 122 { | 96 { |
| 123 CFX_WideString attr; | 97 CFX_WideString attr; |
| 124 GetAttrValue(space, name, attr); | 98 GetAttrValue(space, name, attr); |
| 125 return attr; | 99 return attr; |
| 126 } | 100 } |
| 127 const CFX_WideStringL* GetAttrValuePtr(FX_BSTR space, FX_BSTR name) con
st; | |
| 128 | 101 |
| 129 FX_BOOL GetAttrInteger(FX_BSTR name, int
& attribute) const; | 102 FX_BOOL GetAttrInteger(FX_BSTR name, int
& attribute) const; |
| 130 int GetAttrInteger(FX_BSTR name) con
st | 103 int GetAttrInteger(FX_BSTR name) con
st |
| 131 { | 104 { |
| 132 int attr = 0; | 105 int attr = 0; |
| 133 GetAttrInteger(name, attr); | 106 GetAttrInteger(name, attr); |
| 134 return attr; | 107 return attr; |
| 135 } | 108 } |
| 136 | 109 |
| 137 FX_BOOL GetAttrInteger(FX_BSTR space, FX
_BSTR name, int& attribute) const; | 110 FX_BOOL GetAttrInteger(FX_BSTR space, FX
_BSTR name, int& attribute) const; |
| (...skipping 20 matching lines...) Expand all Loading... |
| 158 return attr; | 131 return attr; |
| 159 } | 132 } |
| 160 | 133 |
| 161 FX_DWORD CountChildren() const; | 134 FX_DWORD CountChildren() const; |
| 162 | 135 |
| 163 enum ChildType { Invalid, Element, Content}; | 136 enum ChildType { Invalid, Element, Content}; |
| 164 | 137 |
| 165 ChildType GetChildType(FX_DWORD index) const; | 138 ChildType GetChildType(FX_DWORD index) const; |
| 166 | 139 |
| 167 CFX_WideString GetContent(FX_DWORD index) const; | 140 CFX_WideString GetContent(FX_DWORD index) const; |
| 168 const CFX_WideStringL* GetContentPtr(FX_DWORD index) const; | |
| 169 | 141 |
| 170 CXML_Element* GetElement(FX_DWORD index) const; | 142 CXML_Element* GetElement(FX_DWORD index) const; |
| 171 | 143 |
| 172 CXML_Element* GetElement(FX_BSTR space, FX_BSTR tag) c
onst | 144 CXML_Element* GetElement(FX_BSTR space, FX_BSTR tag) c
onst |
| 173 { | 145 { |
| 174 return GetElement(space, tag, 0); | 146 return GetElement(space, tag, 0); |
| 175 } | 147 } |
| 176 | 148 |
| 177 FX_DWORD CountElements(FX_BSTR space, FX_BSTR tag
) const; | 149 FX_DWORD CountElements(FX_BSTR space, FX_BSTR tag
) const; |
| 178 | 150 |
| 179 CXML_Element* GetElement(FX_BSTR space, FX_BSTR tag, i
nt index) const; | 151 CXML_Element* GetElement(FX_BSTR space, FX_BSTR tag, i
nt index) const; |
| 180 | 152 |
| 181 FX_DWORD FindElement(CXML_Element *pChild) const; | 153 FX_DWORD FindElement(CXML_Element *pChild) const; |
| 182 | 154 |
| 183 | 155 |
| 184 | 156 |
| 185 | 157 |
| 186 void SetTag(FX_BSTR qSpace, FX_BSTR t
agname); | 158 void SetTag(FX_BSTR qSpace, FX_BSTR t
agname); |
| 187 | 159 |
| 188 void SetTag(FX_BSTR qTagName); | 160 void SetTag(FX_BSTR qTagName); |
| 189 | 161 |
| 190 void RemoveChildren(); | 162 void RemoveChildren(); |
| 191 | 163 |
| 192 void RemoveChild(FX_DWORD index); | 164 void RemoveChild(FX_DWORD index); |
| 193 | 165 |
| 194 | 166 |
| 195 protected: | 167 protected: |
| 196 | 168 |
| 197 CXML_Element* m_pParent; | 169 CXML_Element* m_pParent; |
| 198 | 170 CFX_ByteString» » » m_QSpaceName; |
| 199 CFX_ByteStringL» » » m_QSpaceName; | 171 CFX_ByteString» » » m_TagName; |
| 200 | |
| 201 CFX_ByteStringL» » » m_TagName; | |
| 202 | 172 |
| 203 CXML_AttrMap m_AttrMap; | 173 CXML_AttrMap m_AttrMap; |
| 204 | 174 |
| 205 CFX_PtrArray m_Children; | 175 CFX_PtrArray m_Children; |
| 206 friend class CXML_Parser; | 176 friend class CXML_Parser; |
| 207 friend class CXML_Composer; | 177 friend class CXML_Composer; |
| 208 }; | 178 }; |
| 209 #endif | 179 #endif |
| OLD | NEW |