1
// XMLDocument_as.h: ActionScript 3 "XMLDocument" class, for Gnash.
3
// Copyright (C) 2009 Free Software Foundation, Inc.
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.
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.
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
20
#ifndef GNASH_ASOBJ3_XMLDOCUMENT_H
21
#define GNASH_ASOBJ3_XMLDOCUMENT_H
24
#include "gnashconfig.h"
27
#include "LoadableObject.h"
28
#include "xml/XMLNode_as.h"
31
#include "StringPredicates.h"
39
// Forward declarations
44
/// Implements XML (AS2) and flash.xml.XMLDocument (AS3) class.
46
/// This class interface is identical in AS3 and AS2; it is probably
47
/// included in AS3 for backward compatibility.
48
class XMLDocument_as : public XMLNode_as
54
XML_UNTERMINATED_CDATA = -2,
55
XML_UNTERMINATED_XML_DECL = -3,
56
XML_UNTERMINATED_DOCTYPE_DECL = -4,
57
XML_UNTERMINATED_COMMENT = -5,
58
XML_UNTERMINATED_ELEMENT = -6,
59
XML_OUT_OF_MEMORY = -7,
60
XML_UNTERMINATED_ATTRIBUTE = -8,
61
XML_MISSING_CLOSE_TAG = -9,
62
XML_MISSING_OPEN_TAG = -10
66
XML_LOADED_UNDEFINED = -1,
67
XML_LOADED_FALSE = false,
68
XML_LOADED_TRUE = true
73
XMLDocument_as(const std::string& xml);
77
static void init(as_object& where, const ObjectURI& uri);
78
static void registerNative(as_object& where);
80
/// Convert the XML object to a string
82
/// This calls XMLNode::toString after adding an xmlDecl and
85
/// @param o The ostream to write the string to.
86
/// @param encode Whether to URL encode the node values.
87
void toString(std::ostream& o, bool encode) const;
89
const std::string& getXMLDecl() const {
93
void setXMLDecl(const std::string& xml) {
97
const std::string& getDocTypeDecl() const {
101
void setDocTypeDecl(const std::string& docType) {
102
_docTypeDecl = docType;
107
/// Parses an XML document into the specified XML object tree.
109
/// This reads in an XML file from disk and parses into into a memory
110
/// resident tree which can be walked through later.
112
/// Calls to this function clear any precedently parsed data.
114
void parseXML(const std::string& xml);
116
/// Escape using XML entities.
118
/// Note this is not the same as a URL escape.
119
static void escape(std::string& text);
121
/// Unescape XML entities.
123
/// Note this is not the same as a URL unescape.
124
static void unescape(std::string& text);
126
XMLNode_as* createElement(const std::string& name);
128
XMLNode_as* createTextNode(const std::string& name);
130
ParseStatus status() const {
134
void setStatus(ParseStatus st) {
138
LoadStatus loaded() const {
142
void setLoaded(LoadStatus st) {
148
typedef std::map<std::string, std::string> Entities;
150
static const Entities& getEntities();
152
typedef std::map<std::string, std::string, StringNoCaseLessThan> Attributes;
154
void parseTag(XMLNode_as*& node, const std::string& xml,
155
std::string::const_iterator& it);
157
void parseAttribute(XMLNode_as* node, const std::string& xml,
158
std::string::const_iterator& it, Attributes& attributes);
160
void parseDocTypeDecl(const std::string& xml,
161
std::string::const_iterator& it);
163
void parseText(XMLNode_as* node, const std::string& xml,
164
std::string::const_iterator& it);
166
void parseXMLDecl(const std::string& xml,
167
std::string::const_iterator& it);
169
void parseComment(XMLNode_as* node, const std::string& xml,
170
std::string::const_iterator& it);
172
void parseCData(XMLNode_as* node, const std::string& xml,
173
std::string::const_iterator& it);
175
/// Remove all children
179
/// Return true if ignoreWhite property was set to anything evaluating
181
bool ignoreWhite() const;
183
// -1 if never asked to load anything
184
// 0 if asked to load but not yet loaded (or failure)
185
// 1 if successfully loaded
190
std::string _docTypeDecl;
192
std::string _xmlDecl;
197
// GNASH_ASOBJ3_XMLDOCUMENT_H
202
// indent-tabs-mode: t