]> git.sesse.net Git - casparcg/blob - dependencies64/cef/include/wrapper/cef_xml_object.h
* Merged html producer and updated to latest CEF version (does not have satisfactory...
[casparcg] / dependencies64 / cef / include / wrapper / cef_xml_object.h
1 // Copyright (c) 2011 Marshall A. Greenblatt. All rights reserved.
2 //
3 // Redistribution and use in source and binary forms, with or without
4 // modification, are permitted provided that the following conditions are
5 // met:
6 //
7 //    * Redistributions of source code must retain the above copyright
8 // notice, this list of conditions and the following disclaimer.
9 //    * Redistributions in binary form must reproduce the above
10 // copyright notice, this list of conditions and the following disclaimer
11 // in the documentation and/or other materials provided with the
12 // distribution.
13 //    * Neither the name of Google Inc. nor the name Chromium Embedded
14 // Framework nor the names of its contributors may be used to endorse
15 // or promote products derived from this software without specific prior
16 // written permission.
17 //
18 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 //
30 // ---------------------------------------------------------------------------
31 //
32 // The contents of this file are only available to applications that link
33 // against the libcef_dll_wrapper target.
34 //
35
36 #ifndef CEF_INCLUDE_WRAPPER_CEF_XML_OBJECT_H_
37 #define CEF_INCLUDE_WRAPPER_CEF_XML_OBJECT_H_
38 #pragma once
39
40 #include <map>
41 #include <vector>
42
43 #include "include/base/cef_lock.h"
44 #include "include/base/cef_macros.h"
45 #include "include/base/cef_ref_counted.h"
46 #include "include/cef_base.h"
47 #include "include/cef_xml_reader.h"
48
49 class CefStreamReader;
50
51 ///
52 // Thread safe class for representing XML data as a structured object. This
53 // class should not be used with large XML documents because all data will be
54 // resident in memory at the same time. This implementation supports a
55 // restricted set of XML features:
56 // <pre>
57 // (1) Processing instructions, whitespace and comments are ignored.
58 // (2) Elements and attributes must always be referenced using the fully
59 //     qualified name (ie, namespace:localname).
60 // (3) Empty elements (<a/>) and elements with zero-length values (<a></a>)
61 //     are considered the same.
62 // (4) Element nodes are considered part of a value if:
63 //     (a) The element node follows a non-element node at the same depth
64 //         (see 5), or
65 //     (b) The element node does not have a namespace and the parent node does.
66 // (5) Mixed node types at the same depth are combined into a single element
67 //     value as follows:
68 //     (a) All node values are concatenated to form a single string value.
69 //     (b) Entity reference nodes are resolved to the corresponding entity
70 //         value.
71 //     (c) Element nodes are represented by their outer XML string.
72 // </pre>
73 ///
74 class CefXmlObject : public base::RefCountedThreadSafe<CefXmlObject> {
75  public:
76   typedef std::vector<CefRefPtr<CefXmlObject> > ObjectVector;
77   typedef std::map<CefString, CefString > AttributeMap;
78
79   ///
80   // Create a new object with the specified name. An object name must always be
81   // at least one character long.
82   ///
83   explicit CefXmlObject(const CefString& name);
84
85   ///
86   // Load the contents of the specified XML stream into this object.  The
87   // existing children and attributes, if any, will first be cleared.
88   ///
89   bool Load(CefRefPtr<CefStreamReader> stream,
90             CefXmlReader::EncodingType encodingType,
91             const CefString& URI, CefString* loadError);
92
93   ///
94   // Set the name, children and attributes of this object to a duplicate of the
95   // specified object's contents. The existing children and attributes, if any,
96   // will first be cleared.
97   ///
98   void Set(CefRefPtr<CefXmlObject> object);
99
100   ///
101   // Append a duplicate of the children and attributes of the specified object
102   // to this object. If |overwriteAttributes| is true then any attributes in
103   // this object that also exist in the specified object will be overwritten
104   // with the new values. The name of this object is not changed.
105   ///
106   void Append(CefRefPtr<CefXmlObject> object, bool overwriteAttributes);
107
108   ///
109   // Return a new object with the same name, children and attributes as this
110   // object. The parent of the new object will be NULL.
111   ///
112   CefRefPtr<CefXmlObject> Duplicate();
113
114   ///
115   // Clears this object's children and attributes. The name and parenting of
116   // this object are not changed.
117   ///
118   void Clear();
119
120   ///
121   // Access the object's name. An object name must always be at least one
122   // character long.
123   ///
124   CefString GetName();
125   bool SetName(const CefString& name);
126
127   ///
128   // Access the object's parent. The parent can be NULL if this object has not
129   // been added as the child on another object.
130   ///
131   bool HasParent();
132   CefRefPtr<CefXmlObject> GetParent();
133
134   ///
135   // Access the object's value. An object cannot have a value if it also has
136   // children. Attempting to set the value while children exist will fail.
137   ///
138   bool HasValue();
139   CefString GetValue();
140   bool SetValue(const CefString& value);
141
142   ///
143   // Access the object's attributes. Attributes must have unique names.
144   ///
145   bool HasAttributes();
146   size_t GetAttributeCount();
147   bool HasAttribute(const CefString& name);
148   CefString GetAttributeValue(const CefString& name);
149   bool SetAttributeValue(const CefString& name, const CefString& value);
150   size_t GetAttributes(AttributeMap& attributes);
151   void ClearAttributes();
152
153   ///
154   // Access the object's children. Each object can only have one parent so
155   // attempting to add an object that already has a parent will fail. Removing a
156   // child will set the child's parent to NULL. Adding a child will set the
157   // child's parent to this object. This object's value, if any, will be cleared
158   // if a child is added.
159   ///
160   bool HasChildren();
161   size_t GetChildCount();
162   bool HasChild(CefRefPtr<CefXmlObject> child);
163   bool AddChild(CefRefPtr<CefXmlObject> child);
164   bool RemoveChild(CefRefPtr<CefXmlObject> child);
165   size_t GetChildren(ObjectVector& children);
166   void ClearChildren();
167
168   ///
169   // Find the first child with the specified name.
170   ///
171   CefRefPtr<CefXmlObject> FindChild(const CefString& name);
172
173   ///
174   // Find all children with the specified name.
175   ///
176   size_t FindChildren(const CefString& name, ObjectVector& children);
177
178  private:
179   // Protect against accidental deletion of this object.
180   friend class base::RefCountedThreadSafe<CefXmlObject>;
181   ~CefXmlObject();
182
183   void SetParent(CefXmlObject* parent);
184
185   CefString name_;
186   CefXmlObject* parent_;
187   CefString value_;
188   AttributeMap attributes_;
189   ObjectVector children_;
190
191   base::Lock lock_;
192
193   DISALLOW_COPY_AND_ASSIGN(CefXmlObject);
194 };
195
196 #endif  // CEF_INCLUDE_WRAPPER_CEF_XML_OBJECT_H_