Gnash  0.8.11dev
XMLNode_as.h
Go to the documentation of this file.
1 // XMLNode_as.h: ActionScript 3 "XMLNode" class, for Gnash.
2 //
3 // Copyright (C) 2009, 2010, 2011. 2012 Free Software Foundation, Inc.
4 //
5 // This program is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation; either version 3 of the License, or
8 // (at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software
17 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 //
19 
20 #ifndef GNASH_ASOBJ3_XMLNODE_H
21 #define GNASH_ASOBJ3_XMLNODE_H
22 
23 #include <list>
24 #include <string>
25 #include <cassert>
26 
27 #include "Relay.h"
28 
29 namespace gnash {
30  class as_object;
31  class Global_as;
32  struct ObjectURI;
33 }
34 
35 namespace gnash {
36 
37 
39 //
42 //
53 class XMLNode_as : public Relay
54 {
55 public:
56 
57  enum NodeType {
58  Element = 1,
59  Attribute = 2,
60  Text = 3,
61  Cdata = 4,
62  EntityRef = 5,
63  Entity = 6,
64  ProcInstr = 7,
65  Comment = 8,
66  Document = 9,
67  DocType = 10,
69  Notation = 12
70  };
71 
72  XMLNode_as(Global_as& gl);
73 
74  virtual ~XMLNode_as();
75 
76  size_t length() const { return _children.size(); }
77 
78  const std::string& nodeName() const { return _name; }
79 
80  const std::string& nodeValue() const { return _value; }
81 
83  NodeType nodeType() const { return _type; }
84 
87  _type = type;
88  }
89 
91  void nodeNameSet(const std::string& name) { _name = name; }
92 
93  bool extractPrefix(std::string& prefix) const;
94 
96  void nodeValueSet(const std::string& value) { _value = value; }
97 
99  void getNamespaceForPrefix(const std::string& prefix, std::string& ns)
100  const;
101 
103  //
105  bool getPrefixForNamespace(const std::string& ns, std::string& prefix)
106  const;
107 
108  void setNamespaceURI(const std::string& value) {
109  _namespaceURI = value;
110  }
111 
112  const std::string& getNamespaceURI() const {
113  return _namespaceURI;
114  }
115 
117  bool descendsFrom(XMLNode_as* node) const;
118 
121  bool hasChildNodes() const;
122 
123  XMLNode_as* firstChild() const;
124  XMLNode_as* lastChild() const;
125 
126  // Use a list for quick erasing
127  typedef std::list<XMLNode_as*> Children;
128 
130 
131  XMLNode_as* previousSibling() const;
132  XMLNode_as* nextSibling() const;
133 
135  //
140  XMLNode_as* cloneNode(bool deep) const;
141 
143  //
146  //
148  //
150  void appendChild(XMLNode_as* node);
151 
153  //
156  //
158  //
160  void removeChild(XMLNode_as* node);
161 
164  return _parent;
165  }
166 
168  //
182  void insertBefore(XMLNode_as* newnode, XMLNode_as* pos);
183 
185  //
190  virtual void toString(std::ostream& str, bool encode = false) const;
191 
193  as_object* getAttributes() const { return _attributes; }
194 
196  //
201  void setAttribute(const std::string& name, const std::string& value);
202 
204  //
209  assert(!_object);
210  assert(o);
211  _object = o;
212  }
213 
215  //
217  as_object* object();
218 
219 protected:
220 
222  //
224  virtual void setReachable();
225 
227 
229  //
232  void clearChildren();
233 
234 private:
235 
237  //
239  void setParent(XMLNode_as* node) { _parent = node; }
240 
242  //
246  void updateChildNodes();
247 
249  XMLNode_as(const XMLNode_as &node, bool deep);
250 
251  Children _children;
252 
253  as_object* _object;
254 
255  XMLNode_as* _parent;
256 
257  as_object* _attributes;
258 
259  as_object* _childNodes;
260 
261  std::string _name;
262 
263  std::string _value;
264 
265  NodeType _type;
266 
267  std::string _namespaceURI;
268 
269  static void stringify(const XMLNode_as& xml, std::ostream& xmlout,
270  bool encode);
271 };
272 
273 // Initialize the global XMLNode class
274 void xmlnode_class_init(as_object& where, const ObjectURI& uri);
275 
277 void registerXMLNodeNative(as_object& where);
278 
279 } // gnash namespace
280 
281 // GNASH_ASOBJ3_XMLNODE_H
282 #endif
283 
284 // local Variables:
285 // mode: C++
286 // indent-tabs-mode: t
287 // End:
288 
289 
const std::string & nodeName() const
Definition: XMLNode_as.h:78
bool getPrefixForNamespace(const std::string &ns, std::string &prefix) const
Performs a recursive search of node attributes to find a match.
Definition: XMLNode_as.cpp:322
void setAttribute(const std::string &name, const std::string &value)
Set a named attribute to a value.
Definition: XMLNode_as.cpp:313
XMLNode_as * lastChild() const
Definition: XMLNode_as.cpp:205
const std::string & getNamespaceURI() const
Definition: XMLNode_as.h:112
uri
Definition: test.py:12
XMLNode_as * firstChild() const
Definition: XMLNode_as.cpp:191
XMLNode_as * getParent() const
Get the parent XMLNode_as of this node. Can be 0.
Definition: XMLNode_as.h:163
Definition: XMLNode_as.h:62
as_object * object()
Return the object associated with this XMLNode_as.
Definition: XMLNode_as.cpp:129
Anonymous namespace for callbacks, local functions, event handlers etc.
Definition: dbus_ext.cpp:40
type
Definition: GnashKey.h:329
const std::string & nodeValue() const
Definition: XMLNode_as.h:80
The base class for all ActionScript objects.
Definition: as_object.h:161
XMLNode_as(Global_as &gl)
Definition: XMLNode_as.cpp:79
Definition: GnashKey.h:161
bool hasChildNodes() const
Definition: XMLNode_as.cpp:185
void nodeTypeSet(NodeType type)
Set the type of an XML Node.
Definition: XMLNode_as.h:86
NodeType nodeType() const
Get the type of an XML Node.
Definition: XMLNode_as.h:83
A URI for describing as_objects.
Definition: ObjectURI.h:44
Definition: XMLNode_as.h:61
Definition: XMLNode_as.h:66
void setNamespaceURI(const std::string &value)
Definition: XMLNode_as.h:108
void getNamespaceForPrefix(const std::string &prefix, std::string &ns) const
Performs a recursive search of node attributes to find a match.
Definition: XMLNode_as.cpp:360
Definition: XMLNode_as.h:58
void clearChildren()
Clear all children, making sure unreferenced children are deleted.
Definition: XMLNode_as.cpp:404
virtual void toString(std::ostream &str, bool encode=false) const
Convert the XMLNode to a string.
Definition: XMLNode_as.cpp:307
Definition: XMLNode_as.h:67
void appendChild(XMLNode_as *node)
Append a child node to this XML object.
Definition: XMLNode_as.cpp:222
as_object * childNodes()
Definition: XMLNode_as.cpp:175
void nodeValueSet(const std::string &value)
Set value of this node.
Definition: XMLNode_as.h:96
virtual ~XMLNode_as()
Definition: XMLNode_as.cpp:112
XMLNode_as * nextSibling() const
Definition: XMLNode_as.cpp:288
void nodeNameSet(const std::string &name)
Set name of this node.
Definition: XMLNode_as.h:91
void xmlnode_class_init(as_object &where, const ObjectURI &uri)
Definition: XMLNode_as.cpp:522
bool descendsFrom(XMLNode_as *node) const
Returns true if &#39;this&#39; descends from the specified node.
Definition: XMLNode_as.cpp:231
Definition: XMLNode_as.h:65
The Global object ultimately contains all objects in an ActionScript run.
Definition: Global_as.h:49
XMLNode_as * previousSibling() const
Definition: XMLNode_as.cpp:271
void registerXMLNodeNative(as_object &where)
Register ASnative methods.
Definition: XMLNode_as.cpp:508
This is the base class for type-specific object data.
Definition: Relay.h:49
Global_as & _global
Definition: XMLNode_as.h:226
virtual void setReachable()
Mark reachable elements.
Definition: XMLNode_as.cpp:488
size_t length() const
Definition: XMLNode_as.h:76
Definition: XMLNode_as.h:63
void insertBefore(XMLNode_as *newnode, XMLNode_as *pos)
Insert a node before a node.
Definition: XMLNode_as.cpp:245
Definition: XMLNode_as.h:60
NodeType
Definition: XMLNode_as.h:57
void removeChild(XMLNode_as *node)
Remove a child node from this XML object.
Definition: XMLNode_as.cpp:214
Definition: XMLNode_as.h:64
Definition: XMLNode_as.h:69
A node in an XML tree.
Definition: XMLNode_as.h:53
Definition: XMLNode_as.h:68
as_object * getAttributes() const
Return the attributes object associated with this node.
Definition: XMLNode_as.h:193
XMLNode_as * cloneNode(bool deep) const
Copy a node.
Definition: XMLNode_as.cpp:198
std::string name
Definition: LocalConnection_as.cpp:149
std::list< XMLNode_as * > Children
Definition: XMLNode_as.h:127
void setObject(as_object *o)
Associate an as_object with this XMLNode_as.
Definition: XMLNode_as.h:208
bool extractPrefix(std::string &prefix) const
Definition: XMLNode_as.cpp:389
Definition: XMLNode_as.h:59