Gnash  0.8.10
XMLNode_as.h
Go to the documentation of this file.
00001 // XMLNode_as.h:  ActionScript 3 "XMLNode" class, for Gnash.
00002 //
00003 //   Copyright (C) 2009, 2010, 2011. 2012 Free Software Foundation, Inc.
00004 //
00005 // This program is free software; you can redistribute it and/or modify
00006 // it under the terms of the GNU General Public License as published by
00007 // the Free Software Foundation; either version 3 of the License, or
00008 // (at your option) any later version.
00009 //
00010 // This program is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 // GNU General Public License for more details.
00014 //
00015 // You should have received a copy of the GNU General Public License
00016 // along with this program; if not, write to the Free Software
00017 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
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     // Use a list for quick erasing
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 // Initialize the global XMLNode class
00272 void xmlnode_class_init(as_object& where, const ObjectURI& uri);
00273 
00275 void registerXMLNodeNative(as_object& where);
00276 
00277 } // gnash namespace
00278 
00279 // GNASH_ASOBJ3_XMLNODE_H
00280 #endif
00281 
00282 // local Variables:
00283 // mode: C++
00284 // indent-tabs-mode: t
00285 // End:
00286 
00287