| 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 CORE_INCLUDE_FXCRT_FX_XML_H_ | |
| 8 #define CORE_INCLUDE_FXCRT_FX_XML_H_ | |
| 9 | |
| 10 #include <memory> | |
| 11 #include <vector> | |
| 12 | |
| 13 #include "core/include/fxcrt/fx_basic.h" | |
| 14 | |
| 15 class CXML_AttrItem { | |
| 16 public: | |
| 17 bool Matches(const CFX_ByteStringC& space, const CFX_ByteStringC& name) const; | |
| 18 | |
| 19 CFX_ByteString m_QSpaceName; | |
| 20 CFX_ByteString m_AttrName; | |
| 21 CFX_WideString m_Value; | |
| 22 }; | |
| 23 | |
| 24 class CXML_AttrMap { | |
| 25 public: | |
| 26 const CFX_WideString* Lookup(const CFX_ByteStringC& space, | |
| 27 const CFX_ByteStringC& name) const; | |
| 28 void SetAt(const CFX_ByteStringC& space, | |
| 29 const CFX_ByteStringC& name, | |
| 30 const CFX_WideStringC& value); | |
| 31 int GetSize() const; | |
| 32 CXML_AttrItem& GetAt(int index) const; | |
| 33 | |
| 34 std::unique_ptr<std::vector<CXML_AttrItem>> m_pMap; | |
| 35 }; | |
| 36 | |
| 37 class CXML_Content { | |
| 38 public: | |
| 39 CXML_Content() : m_bCDATA(FALSE), m_Content() {} | |
| 40 void Set(FX_BOOL bCDATA, const CFX_WideStringC& content) { | |
| 41 m_bCDATA = bCDATA; | |
| 42 m_Content = content; | |
| 43 } | |
| 44 | |
| 45 FX_BOOL m_bCDATA; | |
| 46 CFX_WideString m_Content; | |
| 47 }; | |
| 48 | |
| 49 class CXML_Element { | |
| 50 public: | |
| 51 enum ChildType { Invalid, Element, Content }; | |
| 52 | |
| 53 static CXML_Element* Parse(const void* pBuffer, | |
| 54 size_t size, | |
| 55 FX_BOOL bSaveSpaceChars = FALSE, | |
| 56 FX_FILESIZE* pParsedSize = NULL); | |
| 57 static CXML_Element* Parse(IFX_FileRead* pFile, | |
| 58 FX_BOOL bSaveSpaceChars = FALSE, | |
| 59 FX_FILESIZE* pParsedSize = NULL); | |
| 60 static CXML_Element* Parse(IFX_BufferRead* pBuffer, | |
| 61 FX_BOOL bSaveSpaceChars = FALSE, | |
| 62 FX_FILESIZE* pParsedSize = NULL); | |
| 63 | |
| 64 CXML_Element(const CFX_ByteStringC& qSpace, const CFX_ByteStringC& tagName); | |
| 65 CXML_Element(const CFX_ByteStringC& qTagName); | |
| 66 CXML_Element(); | |
| 67 ~CXML_Element(); | |
| 68 | |
| 69 void Empty(); | |
| 70 CFX_ByteString GetTagName(FX_BOOL bQualified = FALSE) const; | |
| 71 CFX_ByteString GetNamespace(FX_BOOL bQualified = FALSE) const; | |
| 72 CFX_ByteString GetNamespaceURI(const CFX_ByteStringC& qName) const; | |
| 73 CXML_Element* GetParent() const { return m_pParent; } | |
| 74 FX_DWORD CountAttrs() const { return m_AttrMap.GetSize(); } | |
| 75 void GetAttrByIndex(int index, | |
| 76 CFX_ByteString& space, | |
| 77 CFX_ByteString& name, | |
| 78 CFX_WideString& value) const; | |
| 79 FX_BOOL HasAttr(const CFX_ByteStringC& qName) const; | |
| 80 FX_BOOL GetAttrValue(const CFX_ByteStringC& name, | |
| 81 CFX_WideString& attribute) const; | |
| 82 CFX_WideString GetAttrValue(const CFX_ByteStringC& name) const { | |
| 83 CFX_WideString attr; | |
| 84 GetAttrValue(name, attr); | |
| 85 return attr; | |
| 86 } | |
| 87 | |
| 88 FX_BOOL GetAttrValue(const CFX_ByteStringC& space, | |
| 89 const CFX_ByteStringC& name, | |
| 90 CFX_WideString& attribute) const; | |
| 91 CFX_WideString GetAttrValue(const CFX_ByteStringC& space, | |
| 92 const CFX_ByteStringC& name) const { | |
| 93 CFX_WideString attr; | |
| 94 GetAttrValue(space, name, attr); | |
| 95 return attr; | |
| 96 } | |
| 97 | |
| 98 FX_BOOL GetAttrInteger(const CFX_ByteStringC& name, int& attribute) const; | |
| 99 int GetAttrInteger(const CFX_ByteStringC& name) const { | |
| 100 int attr = 0; | |
| 101 GetAttrInteger(name, attr); | |
| 102 return attr; | |
| 103 } | |
| 104 | |
| 105 FX_BOOL GetAttrInteger(const CFX_ByteStringC& space, | |
| 106 const CFX_ByteStringC& name, | |
| 107 int& attribute) const; | |
| 108 int GetAttrInteger(const CFX_ByteStringC& space, | |
| 109 const CFX_ByteStringC& name) const { | |
| 110 int attr = 0; | |
| 111 GetAttrInteger(space, name, attr); | |
| 112 return attr; | |
| 113 } | |
| 114 | |
| 115 FX_BOOL GetAttrFloat(const CFX_ByteStringC& name, FX_FLOAT& attribute) const; | |
| 116 FX_FLOAT GetAttrFloat(const CFX_ByteStringC& name) const { | |
| 117 FX_FLOAT attr = 0; | |
| 118 GetAttrFloat(name, attr); | |
| 119 return attr; | |
| 120 } | |
| 121 | |
| 122 FX_BOOL GetAttrFloat(const CFX_ByteStringC& space, | |
| 123 const CFX_ByteStringC& name, | |
| 124 FX_FLOAT& attribute) const; | |
| 125 FX_FLOAT GetAttrFloat(const CFX_ByteStringC& space, | |
| 126 const CFX_ByteStringC& name) const { | |
| 127 FX_FLOAT attr = 0; | |
| 128 GetAttrFloat(space, name, attr); | |
| 129 return attr; | |
| 130 } | |
| 131 | |
| 132 FX_DWORD CountChildren() const { return m_Children.size(); } | |
| 133 ChildType GetChildType(FX_DWORD index) const; | |
| 134 CFX_WideString GetContent(FX_DWORD index) const; | |
| 135 CXML_Element* GetElement(FX_DWORD index) const; | |
| 136 CXML_Element* GetElement(const CFX_ByteStringC& space, | |
| 137 const CFX_ByteStringC& tag) const { | |
| 138 return GetElement(space, tag, 0); | |
| 139 } | |
| 140 | |
| 141 FX_DWORD CountElements(const CFX_ByteStringC& space, | |
| 142 const CFX_ByteStringC& tag) const; | |
| 143 CXML_Element* GetElement(const CFX_ByteStringC& space, | |
| 144 const CFX_ByteStringC& tag, | |
| 145 int index) const; | |
| 146 | |
| 147 FX_DWORD FindElement(CXML_Element* pChild) const; | |
| 148 void SetTag(const CFX_ByteStringC& qSpace, const CFX_ByteStringC& tagname); | |
| 149 void SetTag(const CFX_ByteStringC& qTagName); | |
| 150 void RemoveChildren(); | |
| 151 void RemoveChild(FX_DWORD index); | |
| 152 | |
| 153 protected: | |
| 154 struct ChildRecord { | |
| 155 ChildType type; | |
| 156 void* child; // CXML_Element and CXML_Content lack a common ancestor. | |
| 157 }; | |
| 158 | |
| 159 CXML_Element* m_pParent; | |
| 160 CFX_ByteString m_QSpaceName; | |
| 161 CFX_ByteString m_TagName; | |
| 162 CXML_AttrMap m_AttrMap; | |
| 163 std::vector<ChildRecord> m_Children; | |
| 164 | |
| 165 friend class CXML_Parser; | |
| 166 friend class CXML_Composer; | |
| 167 }; | |
| 168 | |
| 169 #endif // CORE_INCLUDE_FXCRT_FX_XML_H_ | |
| OLD | NEW |