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 {
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 
const std::string & getContentType() const
Definition: XML_as.h:104
ParseStatus
Definition: XML_as.h:50
std::string::const_iterator xml_iterator
Definition: XML_as.h:48
Definition: XML_as.h:57
const std::string & getDocTypeDecl() const
Definition: XML_as.h:96
uri
Definition: test.py:12
void registerXMLNative(as_object &where)
Register XML native functions.
Definition: XML_as.cpp:540
Anonymous namespace for callbacks, local functions, event handlers etc.
Definition: dbus_ext.cpp:40
void setContentType(const std::string &contentType)
Definition: XML_as.h:108
~XML_as()
Definition: XML_as.h:77
XML_as(as_object &object)
Create an XML object.
Definition: XML_as.cpp:79
The base class for all ActionScript objects.
Definition: as_object.h:161
Definition: GnashKey.h:161
Definition: XML_as.h:51
bool ignoreWhite() const
Return current ignoreWhite property.
Definition: XML_as.h:140
void setXMLDecl(const std::string &xml)
Definition: XML_as.h:92
A URI for describing as_objects.
Definition: ObjectURI.h:44
Implements XML (AS2) and flash.xml.XMLDocument (AS3) class.
Definition: XML_as.h:44
void setLoaded(LoadStatus st)
Definition: XML_as.h:135
void ignoreWhite(bool ignore)
Set ignoreWhite property.
Definition: XML_as.h:145
void xml_class_init(as_object &where, const ObjectURI &uri)
Register the XML class.
Definition: XML_as.cpp:519
const std::string & getXMLDecl() const
Definition: XML_as.h:88
void unescapeXML(std::string &text)
Definition: XML_as.cpp:115
Definition: XML_as.h:66
Definition: XML_as.h:65
LoadStatus loaded() const
Definition: XML_as.h:131
int status() const
Definition: XML_as.h:123
pixel_iterator< T > end(GnashImage &im)
Definition: ImageIterators.h:198
void toString(std::ostream &o, bool encode) const
Convert the XML object to a string.
Definition: XML_as.cpp:129
A node in an XML tree.
Definition: XMLNode_as.h:53
void escapeXML(std::string &text)
Escape using XML entities.
Definition: XML_as.cpp:104
void setStatus(ParseStatus st)
Definition: XML_as.h:127
void setDocTypeDecl(const std::string &docType)
Definition: XML_as.h:100
void parseXML(const std::string &xml)
Parses an XML document into the specified XML object tree.
Definition: XML_as.cpp:458
LoadStatus
Definition: XML_as.h:63