Gnash  0.8.11dev
XML_as.h
Go to the documentation of this file.
1 // XML_as.h: ActionScript 3 "XMLDocument" 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_XMLDOCUMENT_H
21 #define GNASH_ASOBJ3_XMLDOCUMENT_H
22 
23 #include "XMLNode_as.h"
24 #include "dsodefs.h"
25 #include "StringPredicates.h"
26 
27 #include <map>
28 #include <string>
29 
30 
31 namespace gnash {
32 
33 // Forward declarations
34 class fn_call;
35 class URL;
36 
38 //
41 //
44 class XML_as : public XMLNode_as
45 {
46 public:
47 
48  typedef std::string::const_iterator xml_iterator;
49 
50  enum ParseStatus {
51  XML_OK = 0,
61  };
62 
63  enum LoadStatus {
66  XML_LOADED_TRUE = true
67  };
68 
70  //
73  XML_as(as_object& object);
74 
75  XML_as(as_object& object, const std::string& xml);
76 
77  ~XML_as() {};
78 
80  //
83  //
86  void toString(std::ostream& o, bool encode) const;
87 
88  const std::string& getXMLDecl() const {
89  return _xmlDecl;
90  }
91 
92  void setXMLDecl(const std::string& xml) {
93  _xmlDecl = xml;
94  }
95 
96  const std::string& getDocTypeDecl() const {
97  return _docTypeDecl;
98  }
99 
100  void setDocTypeDecl(const std::string& docType) {
101  _docTypeDecl = docType;
102  }
103 
104  const std::string& getContentType() const {
105  return _contentType;
106  }
107 
108  void setContentType(const std::string& contentType) {
109  _contentType = contentType;
110  }
111 
112  // Methods
113 
115  //
121  void parseXML(const std::string& xml);
122 
123  int status() const {
124  return _status;
125  }
126 
128  _status = st;
129  }
130 
131  LoadStatus loaded() const {
132  return _loaded;
133  }
134 
136  _loaded = st;
137  }
138 
140  bool ignoreWhite() const {
141  return _ignoreWhite;
142  }
143 
145  void ignoreWhite(bool ignore) {
146  _ignoreWhite = ignore;
147  }
148 
149 private:
150 
151  typedef std::map<std::string, std::string, StringNoCaseLessThan> Attributes;
152 
153  void parseTag(XMLNode_as*& node, xml_iterator& it, xml_iterator end);
154 
155  void parseAttribute(XMLNode_as* node, xml_iterator& it,
156  xml_iterator end, Attributes& attributes);
157 
158  void parseDocTypeDecl( xml_iterator& it, xml_iterator end);
159 
160  void parseText(XMLNode_as* node, xml_iterator& it, xml_iterator end,
161  bool ignoreWhite);
162 
163  void parseXMLDecl(xml_iterator& it, xml_iterator end);
164 
165  void parseComment(XMLNode_as* node, xml_iterator& it, xml_iterator end);
166 
167  void parseCData(XMLNode_as* node, xml_iterator& it, xml_iterator end);
168 
170  //
173  void clear();
174 
175  // -1 if never asked to load anything
176  // 0 if asked to load but not yet loaded (or failure)
177  // 1 if successfully loaded
178  LoadStatus _loaded;
179 
180  // Nominally used to store ParseStatus, but can be any int value.
181  int _status;
182 
183  std::string _docTypeDecl;
184 
185  std::string _xmlDecl;
186 
187  std::string _contentType;
188 
189  bool _ignoreWhite;
190 };
191 
192 
194 //
196 void escapeXML(std::string& text);
197 void unescapeXML(std::string& text);
198 
200 void xml_class_init(as_object& where, const ObjectURI& uri);
201 
203 void registerXMLNative(as_object& where);
204 
205 } // namespace gnash
206 #endif
207 
208 // local Variables:
209 // mode: C++
210 // indent-tabs-mode: t
211 // End:
212 
gnash::NSV::PROP_ON_LOAD
@ PROP_ON_LOAD
Definition: namedStrings.h:160
gnash::XML_as::toString
void toString(std::ostream &o, bool encode) const
Convert the XML object to a string.
Definition: XML_as.cpp:129
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::toNumber
double toNumber(const as_value &v, const VM &vm)
Convert an as_value to a double.
Definition: VM.cpp:451
gnash::XML_as::XML_OUT_OF_MEMORY
@ XML_OUT_OF_MEMORY
Definition: XML_as.h:57
gnash::XML_as::setStatus
void setStatus(ParseStatus st)
Definition: XML_as.h:127
gnash::XML_as::ParseStatus
ParseStatus
Definition: XML_as.h:50
gnash::XML_as::XML_UNTERMINATED_ATTRIBUTE
@ XML_UNTERMINATED_ATTRIBUTE
Definition: XML_as.h:58
name
std::string name
Definition: LocalConnection_as.cpp:149
gnash::isNaN
bool isNaN(const T &num)
Definition: GnashNumeric.h:62
gnash::attachLoadableInterface
void attachLoadableInterface(as_object &o, int flags)
Attach some common AS code for Loadable objects.
Definition: LoadableObject.cpp:55
gnash::XML_as::XML_OK
@ XML_OK
Definition: XML_as.h:51
gnash::XML_as::xml_iterator
std::string::const_iterator xml_iterator
Definition: XML_as.h:48
gnash::toBool
bool toBool(const as_value &v, const VM &vm)
Convert an as_value to boolean type.
Definition: VM.cpp:445
gnash::as_object
The base class for all ActionScript objects.
Definition: as_object.h:162
gnash::XML_as::XML_LOADED_UNDEFINED
@ XML_LOADED_UNDEFINED
Definition: XML_as.h:64
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::XML_as::XML_UNTERMINATED_DOCTYPE_DECL
@ XML_UNTERMINATED_DOCTYPE_DECL
Definition: XML_as.h:54
gnash::XMLNode_as::XMLNode_as
XMLNode_as(Global_as &gl)
Definition: XMLNode_as.cpp:79
gnash::XML_as::setContentType
void setContentType(const std::string &contentType)
Definition: XML_as.h:108
gnash::XMLNode_as::getNamespaceURI
const std::string & getNamespaceURI() const
Definition: XMLNode_as.h:112
dsodefs.h
gnash::XML_as::XML_LOADED_FALSE
@ XML_LOADED_FALSE
Definition: XML_as.h:65
gnash::XMLNode_as::firstChild
XMLNode_as * firstChild() const
Definition: XMLNode_as.cpp:191
gnash::key::i
@ i
Definition: GnashKey.h:155
gnash::XML_as::XML_as
XML_as(as_object &object)
Create an XML object.
Definition: XML_as.cpp:79
_
#define _(String)
Definition: log.h:44
gnash::as_environment
Provides information about timeline context.
Definition: as_environment.h:51
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
gnash::XML_as::ignoreWhite
bool ignoreWhite() const
Return current ignoreWhite property.
Definition: XML_as.h:140
gnash::NSV::PROP_PARSE_XML
@ PROP_PARSE_XML
Definition: namedStrings.h:183
gnash::key::s
@ s
Definition: GnashKey.h:165
gnash::XML_as::XML_MISSING_CLOSE_TAG
@ XML_MISSING_CLOSE_TAG
Definition: XML_as.h:59
gnash::XML_as::getDocTypeDecl
const std::string & getDocTypeDecl() const
Definition: XML_as.h:96
gnash::XMLNode_as::_global
Global_as & _global
Definition: XMLNode_as.h:226
NativeFunction.h
Global_as.h
gnash::getGlobal
Global_as & getGlobal(const as_environment &env)
Definition: as_environment.cpp:651
gnash::getVM
VM & getVM(const as_environment &env)
Definition: as_environment.h:222
gnash::XMLNode_as::setNamespaceURI
void setNamespaceURI(const std::string &value)
Definition: XMLNode_as.h:108
as_function.h
gnash::log_error
void log_error(StringType msg, Args... args)
Definition: log.h:283
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::XML_as::XML_MISSING_OPEN_TAG
@ XML_MISSING_OPEN_TAG
Definition: XML_as.h:60
gnash::XML_as::setXMLDecl
void setXMLDecl(const std::string &xml)
Definition: XML_as.h:92
gnash::XML_as::~XML_as
~XML_as()
Definition: XML_as.h:77
gnash::as_object::DefaultFlags
static const int DefaultFlags
The most common flags for built-in properties.
Definition: as_object.h:192
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::registerXMLNative
void registerXMLNative(as_object &where)
Register XML native functions.
Definition: XML_as.cpp:540
gnash::XML_as::getXMLDecl
const std::string & getXMLDecl() const
Definition: XML_as.h:88
gnash::Global_as::createClass
as_object * createClass(Global_as::ASFunction ctor, as_object *prototype)
Create an ActionScript class.
Definition: Global_as.cpp:180
StringPredicates.h
gnash::XMLNode_as::setObject
void setObject(as_object *o)
Associate an as_object with this XMLNode_as.
Definition: XMLNode_as.h:208
gnash::as_value::to_function
as_function * to_function() const
Return the value as a function only if it is a function.
Definition: as_value.cpp:499
gnash::XML_as::setLoaded
void setLoaded(LoadStatus st)
Definition: XML_as.h:135
gnash::XML_as::XML_UNTERMINATED_COMMENT
@ XML_UNTERMINATED_COMMENT
Definition: XML_as.h:55
gnash::FunctionArgs
A class to contain transferable arguments for a fn_call.
Definition: fn_call.h:57
gnash::XML_as::XML_UNTERMINATED_XML_DECL
@ XML_UNTERMINATED_XML_DECL
Definition: XML_as.h:53
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::emptyFunction
as_value emptyFunction(const fn_call &)
Definition: Global_as.h:256
gnash::constructInstance
as_object * constructInstance(as_function &ctor, const as_environment &env, fn_call::Args &args)
Definition: as_function.cpp:47
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::XML_as::XML_UNTERMINATED_CDATA
@ XML_UNTERMINATED_CDATA
Definition: XML_as.h:52
Object.h
gnash::XML_as::ignoreWhite
void ignoreWhite(bool ignore)
Set ignoreWhite property.
Definition: XML_as.h:145
gnash::XMLNode_as::Element
@ Element
Definition: XMLNode_as.h:58
VM.h
gnash::log_aserror
void log_aserror(StringType msg, Args... args)
Definition: log.h:331
XML_as.h
log.h
gnash::XMLNode_as::Text
@ Text
Definition: XMLNode_as.h:60
fn_call.h
gnash::NSV::PROP_LOADED
@ PROP_LOADED
Definition: namedStrings.h:84
gnash::XMLNode_as::nodeName
const std::string & nodeName() const
Definition: XMLNode_as.h:78
gnash::image::end
pixel_iterator< T > end(GnashImage &im)
Definition: ImageIterators.h:198
namedStrings.h
gnash::Global_as
The Global object ultimately contains all objects in an ActionScript run.
Definition: Global_as.h:50
gnash::XMLNode_as::getParent
XMLNode_as * getParent() const
Get the parent XMLNode_as of this node. Can be 0.
Definition: XMLNode_as.h:163
gnash::getSWFVersion
int getSWFVersion(const as_environment &env)
Definition: as_environment.cpp:657
test.uri
uri
Definition: test.py:12
gnash::XML_as
Implements XML (AS2) and flash.xml.XMLDocument (AS3) class.
Definition: XML_as.h:45
gnash::XML_as::XML_UNTERMINATED_ELEMENT
@ XML_UNTERMINATED_ELEMENT
Definition: XML_as.h:56
gnash::getURI
ObjectURI getURI(const VM &vm, const std::string &str, bool lowerCaseHint=false)
Definition: VM.h:290
gnash::equal
bool equal(string_table &st, string_table::key a, string_table::key b, bool caseless)
Check whether two keys are equivalent.
Definition: string_table.cpp:174
gnash::NSV::CLASS_XMLNODE
@ CLASS_XMLNODE
Definition: namedStrings.h:259
gnash::XML_as::loaded
LoadStatus loaded() const
Definition: XML_as.h:131
gnash::XML_as::status
int status() const
Definition: XML_as.h:123
gnash::key::o
@ o
Definition: GnashKey.h:161
gnash::NSV::PROP_PROTOTYPE
@ PROP_PROTOTYPE
Definition: namedStrings.h:87
gnash::ObjectURI
A URI for describing as_objects.
Definition: ObjectURI.h:45
gnash::unescapeXML
void unescapeXML(std::string &text)
Definition: XML_as.cpp:115
LoadableObject.h
gnash::xml_class_init
void xml_class_init(as_object &where, const ObjectURI &uri)
Register the XML class.
Definition: XML_as.cpp:519
gnash::XML_as::getContentType
const std::string & getContentType() const
Definition: XML_as.h:104
gnash::key::e
@ e
Definition: GnashKey.h:151
gnash::XML_as::setDocTypeDecl
void setDocTypeDecl(const std::string &docType)
Definition: XML_as.h:100
gnash::XML_as::parseXML
void parseXML(const std::string &xml)
Parses an XML document into the specified XML object tree.
Definition: XML_as.cpp:458
gnash::XML_as::XML_LOADED_TRUE
@ XML_LOADED_TRUE
Definition: XML_as.h:66
gnash::as_function
ActionScript Function, either builtin or SWF-defined.
Definition: as_function.h:63
gnash::XML_as::LoadStatus
LoadStatus
Definition: XML_as.h:63