Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef GNASH_ASOBJ3_XMLNODE_H
00021 #define GNASH_ASOBJ3_XMLNODE_H
00022
00023 #include <list>
00024 #include <string>
00025 #include <cassert>
00026
00027 #include "Relay.h"
00028
00029 namespace gnash {
00030 class as_object;
00031 class Global_as;
00032 struct ObjectURI;
00033 }
00034
00035 namespace gnash {
00036
00037
00039
00042
00053 class XMLNode_as : public Relay
00054 {
00055 public:
00056
00057 enum NodeType {
00058 Element = 1,
00059 Attribute = 2,
00060 Text = 3,
00061 Cdata = 4,
00062 EntityRef = 5,
00063 Entity = 6,
00064 ProcInstr = 7,
00065 Comment = 8,
00066 Document = 9,
00067 DocType = 10,
00068 DocFragment = 11,
00069 Notation = 12
00070 };
00071
00072 XMLNode_as(Global_as& gl);
00073
00074 virtual ~XMLNode_as();
00075
00076 size_t length() const { return _children.size(); }
00077
00078 const std::string& nodeName() const { return _name; }
00079
00080 const std::string& nodeValue() const { return _value; }
00081
00083 NodeType nodeType() const { return _type; }
00084
00086 void nodeTypeSet(NodeType type) {
00087 _type = type;
00088 }
00089
00091 void nodeNameSet(const std::string& name) { _name = name; }
00092
00093 bool extractPrefix(std::string& prefix) const;
00094
00096 void nodeValueSet(const std::string& value) { _value = value; }
00097
00099 void getNamespaceForPrefix(const std::string& prefix, std::string& ns)
00100 const;
00101
00103
00105 bool getPrefixForNamespace(const std::string& ns, std::string& prefix)
00106 const;
00107
00108 void setNamespaceURI(const std::string& value) {
00109 _namespaceURI = value;
00110 }
00111
00112 const std::string& getNamespaceURI() const {
00113 return _namespaceURI;
00114 }
00115
00118 bool hasChildNodes() const;
00119
00120 XMLNode_as* firstChild() const;
00121 XMLNode_as* lastChild() const;
00122
00123
00124 typedef std::list<XMLNode_as*> Children;
00125
00126 as_object* childNodes();
00127
00128 XMLNode_as* previousSibling() const;
00129 XMLNode_as* nextSibling() const;
00130
00132
00137 XMLNode_as* cloneNode(bool deep) const;
00138
00140
00143
00145
00147 void appendChild(XMLNode_as* node);
00148
00150
00153
00155
00157 void removeChild(XMLNode_as* node);
00158
00160 XMLNode_as* getParent() const {
00161 return _parent;
00162 }
00163
00165
00179 void insertBefore(XMLNode_as* newnode, XMLNode_as* pos);
00180
00182
00187 virtual void toString(std::ostream& str, bool encode = false) const;
00188
00190 as_object* getAttributes() const { return _attributes; }
00191
00193
00198 void setAttribute(const std::string& name, const std::string& value);
00199
00201
00205 void setObject(as_object* o) {
00206 assert(!_object);
00207 assert(o);
00208 _object = o;
00209 }
00210
00212
00214 as_object* object();
00215
00216 protected:
00217
00219
00221 virtual void setReachable();
00222
00223 Global_as& _global;
00224
00226
00229 void clearChildren();
00230
00231 private:
00232
00234
00236 void setParent(XMLNode_as* node) { _parent = node; }
00237
00239
00243 void updateChildNodes();
00244
00246 XMLNode_as(const XMLNode_as &node, bool deep);
00247
00248 Children _children;
00249
00250 as_object* _object;
00251
00252 XMLNode_as* _parent;
00253
00254 as_object* _attributes;
00255
00256 as_object* _childNodes;
00257
00258 std::string _name;
00259
00260 std::string _value;
00261
00262 NodeType _type;
00263
00264 std::string _namespaceURI;
00265
00266 static void stringify(const XMLNode_as& xml, std::ostream& xmlout,
00267 bool encode);
00268
00269 };
00270
00271
00272 void xmlnode_class_init(as_object& where, const ObjectURI& uri);
00273
00275 void registerXMLNodeNative(as_object& where);
00276
00277 }
00278
00279
00280 #endif
00281
00282
00283
00284
00285
00286
00287