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  ParseStatus 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  ParseStatus _status;
181 
182  std::string _docTypeDecl;
183 
184  std::string _xmlDecl;
185 
186  std::string _contentType;
187 
188  bool _ignoreWhite;
189 };
190 
191 
193 //
195 void escapeXML(std::string& text);
196 void unescapeXML(std::string& text);
197 
199 void xml_class_init(as_object& where, const ObjectURI& uri);
200 
202 void registerXMLNative(as_object& where);
203 
204 } // namespace gnash
205 #endif
206 
207 // local Variables:
208 // mode: C++
209 // indent-tabs-mode: t
210 // End:
211