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 
gnash::XMLNode_as::previousSibling
XMLNode_as * previousSibling() const
Definition: XMLNode_as.cpp:271
gnash::isNativeType
bool isNativeType(const as_object *obj, T *&relay)
Check whether the object is an instance of a known type.
Definition: as_object.h:875
gnash::XMLNode_as::insertBefore
void insertBefore(XMLNode_as *newnode, XMLNode_as *pos)
Insert a node before a node.
Definition: XMLNode_as.cpp:245
gnash::XMLNode_as::nextSibling
XMLNode_as * nextSibling() const
Definition: XMLNode_as.cpp:288
gnash::arrayKey
ObjectURI arrayKey(VM &vm, size_t i)
Convert an integral value into an ObjectURI.
Definition: Array_as.cpp:995
gnash::as_object::set_member_flags
void set_member_flags(const ObjectURI &uri, int setTrue, int setFalse=0)
Set member flags (probably used by ASSetPropFlags)
Definition: as_object.cpp:753
gnash::XMLNode_as::~XMLNode_as
virtual ~XMLNode_as()
Definition: XMLNode_as.cpp:112
name
std::string name
Definition: LocalConnection_as.cpp:149
gnash::XMLNode_as::NodeType
NodeType
Definition: XMLNode_as.h:57
gnash::toBool
bool toBool(const as_value &v, const VM &vm)
Convert an as_value to boolean type.
Definition: VM.cpp:445
gnash::toInt
std::int32_t toInt(const as_value &v, const VM &vm)
AS2-compatible conversion to 32bit integer.
Definition: VM.cpp:463
_object
as_object * _object
Definition: Array_as.cpp:680
gnash::as_object
The base class for all ActionScript objects.
Definition: as_object.h:162
gnash::XMLNode_as::getAttributes
as_object * getAttributes() const
Return the attributes object associated with this node.
Definition: XMLNode_as.h:193
gnash::XMLNode_as
A node in an XML tree.
Definition: XMLNode_as.h:54
gnash::toObject
as_object * toObject(const as_value &v, VM &vm)
Convert an as_value to an object.
Definition: VM.cpp:457
gnash::XMLNode_as::XMLNode_as
XMLNode_as(Global_as &gl)
Definition: XMLNode_as.cpp:79
gnash::XMLNode_as::getNamespaceURI
const std::string & getNamespaceURI() const
Definition: XMLNode_as.h:112
gnash::registerXMLNodeNative
void registerXMLNodeNative(as_object &where)
Register ASnative methods.
Definition: XMLNode_as.cpp:508
gnash::log_debug
void log_debug(StringType msg, Args... args)
Definition: log.h:301
gnash::XMLNode_as::firstChild
XMLNode_as * firstChild() const
Definition: XMLNode_as.cpp:191
gnash::key::i
@ i
Definition: GnashKey.h:155
gnash::NSV::PROP_LENGTH
@ PROP_LENGTH
Definition: namedStrings.h:83
_
#define _(String)
Definition: log.h:44
gnash::XMLNode_as::EntityRef
@ EntityRef
Definition: XMLNode_as.h:62
gnash::as_object::init_member
void init_member(const std::string &name, const as_value &val, int flags=DefaultFlags)
Initialize a member value by string.
Definition: as_object.cpp:669
gnash::VM
The AVM1 virtual machine.
Definition: VM.h:72
gnash
Anonymous namespace for callbacks, local functions, event handlers etc.
Definition: dbus_ext.cpp:41
PropertyList.h
gnash::XMLNode_as::_global
Global_as & _global
Definition: XMLNode_as.h:226
NativeFunction.h
Global_as.h
gnash::XMLNode_as::hasChildNodes
bool hasChildNodes() const
Definition: XMLNode_as.cpp:185
gnash::getGlobal
Global_as & getGlobal(const as_environment &env)
Definition: as_environment.cpp:651
gnash::XMLNode_as::childNodes
as_object * childNodes()
Definition: XMLNode_as.cpp:175
gnash::NSV::PROP_CONSTRUCTOR
@ PROP_CONSTRUCTOR
Definition: namedStrings.h:68
gnash::getVM
VM & getVM(const as_environment &env)
Definition: as_environment.h:222
gnash::XMLNode_as::setReachable
virtual void setReachable()
Mark reachable elements.
Definition: XMLNode_as.cpp:488
gnash::XMLNode_as::setNamespaceURI
void setNamespaceURI(const std::string &value)
Definition: XMLNode_as.h:108
gnash::XMLNode_as::getNamespaceForPrefix
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
gnash::getMember
as_value getMember(as_object &o, const ObjectURI &uri)
Get a member of an object using AS lookup rules.
Definition: as_object.h:756
gnash::escapeXML
void escapeXML(std::string &text)
Escape using XML entities.
Definition: XML_as.cpp:104
gnash::XMLNode_as::removeChild
void removeChild(XMLNode_as *node)
Remove a child node from this XML object.
Definition: XMLNode_as.cpp:214
gnash::createObject
as_object * createObject(const Global_as &gl)
Definition: Global_as.cpp:303
gnash::XMLNode_as::nodeValueSet
void nodeValueSet(const std::string &value)
Set value of this node.
Definition: XMLNode_as.h:96
gnash::enumerateProperties
SortedPropertyList enumerateProperties(as_object &obj)
Enumerate all non-hidden properties to the passed container.
Definition: as_object.cpp:1069
gnash::SortedPropertyList
std::vector< std::pair< ObjectURI, as_value > > SortedPropertyList
This is used to hold an intermediate copy of an as_object's properties.
Definition: as_object.h:887
gnash::as_object::DefaultFlags
static const int DefaultFlags
The most common flags for built-in properties.
Definition: as_object.h:192
gnash::xmlnode_class_init
void xmlnode_class_init(as_object &where, const ObjectURI &uri)
Definition: XMLNode_as.cpp:522
gnash::callMethod
as_value callMethod(fn_call::Args &args, as_object *obj, const ObjectURI &uri)
Call a member function of this object in an AS-compatible way.
Definition: Global_as.h:219
gnash::renderer::opengl::for_each
void for_each(C &container, R(T::*pmf)(const A &), const A &arg)
Definition: Renderer_ogl.cpp:690
gnash::Relay
This is the base class for type-specific object data.
Definition: Relay.h:50
gnash::Global_as::createClass
as_object * createClass(Global_as::ASFunction ctor, as_object *prototype)
Create an ActionScript class.
Definition: Global_as.cpp:180
gnash::XMLNode_as::cloneNode
XMLNode_as * cloneNode(bool deep) const
Copy a node.
Definition: XMLNode_as.cpp:198
gnash::XMLNode_as::setObject
void setObject(as_object *o)
Associate an as_object with this XMLNode_as.
Definition: XMLNode_as.h:208
gnash::XMLNode_as::extractPrefix
bool extractPrefix(std::string &prefix) const
Definition: XMLNode_as.cpp:389
gnash::key::type
type
Definition: GnashKey.h:330
gnash::as_value::to_string
DSOTEXPORT std::string to_string(int version=7) const
Get a std::string representation for this value.
Definition: as_value.cpp:205
XMLNode_as.h
gnash::XMLNode_as::appendChild
void appendChild(XMLNode_as *node)
Append a child node to this XML object.
Definition: XMLNode_as.cpp:222
IF_VERBOSE_ASCODING_ERRORS
#define IF_VERBOSE_ASCODING_ERRORS(x)
Definition: log.h:397
gnash::XMLNode_as::nodeType
NodeType nodeType() const
Get the type of an XML Node.
Definition: XMLNode_as.h:83
gnash::XMLNode_as::Cdata
@ Cdata
Definition: XMLNode_as.h:61
gnash::XMLNode_as::Document
@ Document
Definition: XMLNode_as.h:66
gnash::VM::registerNative
void registerNative(as_c_function_ptr fun, unsigned int x, unsigned int y)
Definition: VM.cpp:268
gnash::XMLNode_as::clearChildren
void clearChildren()
Clear all children, making sure unreferenced children are deleted.
Definition: XMLNode_as.cpp:404
gnash::XMLNode_as::setAttribute
void setAttribute(const std::string &name, const std::string &value)
Set a named attribute to a value.
Definition: XMLNode_as.cpp:313
gnash::XMLNode_as::toString
virtual void toString(std::ostream &str, bool encode=false) const
Convert the XMLNode to a string.
Definition: XMLNode_as.cpp:307
gnash::key::_1
@ _1
Definition: GnashKey.h:95
gnash::XMLNode_as::descendsFrom
bool descendsFrom(XMLNode_as *node) const
Returns true if 'this' descends from the specified node.
Definition: XMLNode_as.cpp:231
gnash::XMLNode_as::DocType
@ DocType
Definition: XMLNode_as.h:67
Object.h
gnash::XMLNode_as::Element
@ Element
Definition: XMLNode_as.h:58
gnash::Global_as::createArray
as_object * createArray()
Construct an Array.
Definition: Global_as.cpp:207
gnash::XMLNode_as::nodeNameSet
void nodeNameSet(const std::string &name)
Set name of this node.
Definition: XMLNode_as.h:91
VM.h
gnash::XMLNode_as::nodeValue
const std::string & nodeValue() const
Definition: XMLNode_as.h:80
gnash::XMLNode_as::nodeTypeSet
void nodeTypeSet(NodeType type)
Set the type of an XML Node.
Definition: XMLNode_as.h:86
gnash::XMLNode_as::Children
std::list< XMLNode_as * > Children
Definition: XMLNode_as.h:127
gnash::XMLNode_as::lastChild
XMLNode_as * lastChild() const
Definition: XMLNode_as.cpp:205
gnash::log_aserror
void log_aserror(StringType msg, Args... args)
Definition: log.h:331
XML_as.h
Relay.h
log.h
gnash::XMLNode_as::Text
@ Text
Definition: XMLNode_as.h:60
fn_call.h
gnash::XMLNode_as::ProcInstr
@ ProcInstr
Definition: XMLNode_as.h:64
gnash::XMLNode_as::nodeName
const std::string & nodeName() const
Definition: XMLNode_as.h:78
gnash::XMLNode_as::Entity
@ Entity
Definition: XMLNode_as.h:63
gnash::XMLNode_as::Notation
@ Notation
Definition: XMLNode_as.h:69
gnash::XMLNode_as::getPrefixForNamespace
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
namedStrings.h
gnash::Global_as
The Global object ultimately contains all objects in an ActionScript run.
Definition: Global_as.h:50
gnash::as_object::set_member
virtual bool set_member(const ObjectURI &uri, const as_value &val, bool ifFound=false)
Set a member value.
Definition: as_object.cpp:583
gnash::XMLNode_as::getParent
XMLNode_as * getParent() const
Get the parent XMLNode_as of this node. Can be 0.
Definition: XMLNode_as.h:163
test.uri
uri
Definition: test.py:12
gnash::getStringTable
string_table & getStringTable(const as_environment &env)
Definition: as_environment.cpp:639
gnash::XMLNode_as::Comment
@ Comment
Definition: XMLNode_as.h:65
gnash::XMLNode_as::object
as_object * object()
Return the object associated with this XMLNode_as.
Definition: XMLNode_as.cpp:129
gnash::XMLNode_as::DocFragment
@ DocFragment
Definition: XMLNode_as.h:68
gnash::getURI
ObjectURI getURI(const VM &vm, const std::string &str, bool lowerCaseHint=false)
Definition: VM.h:290
Array_as.h
gnash::NSV::CLASS_XMLNODE
@ CLASS_XMLNODE
Definition: namedStrings.h:259
gnash::NSV::PROP_ESCAPE
@ PROP_ESCAPE
Definition: namedStrings.h:75
gnash::key::o
@ o
Definition: GnashKey.h:161
gnash::PropFlags::readOnly
@ readOnly
Protect from assigning a value.
Definition: PropFlags.h:42
gnash::NSV::PROP_PROTOTYPE
@ PROP_PROTOTYPE
Definition: namedStrings.h:87
gnash::ObjectURI
A URI for describing as_objects.
Definition: ObjectURI.h:45
gnash::XMLNode_as::Attribute
@ Attribute
Definition: XMLNode_as.h:59
gnash::key::e
@ e
Definition: GnashKey.h:151
gnash::XMLNode_as::length
size_t length() const
Definition: XMLNode_as.h:76
gnash::GcResource::setReachable
void setReachable() const
Mark this resource as being reachable.
Definition: GC.h:92