1 // XML_as.h: ActionScript 3 "XMLDocument" class, for Gnash.
3 // Copyright (C) 2009, 2010 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
23 #include "XMLNode_as.h"
25 #include "StringPredicates.h"
33 // Forward declarations
37 /// Implements XML (AS2) and flash.xml.XMLDocument (AS3) class.
39 /// This class interface is identical in AS3 and AS2; it is probably
40 /// included in AS3 for backward compatibility.
42 /// The class definition is necessary because XML is encoded differently
44 class XML_as
: public XMLNode_as
48 typedef std::string::const_iterator xml_iterator
;
52 XML_UNTERMINATED_CDATA
= -2,
53 XML_UNTERMINATED_XML_DECL
= -3,
54 XML_UNTERMINATED_DOCTYPE_DECL
= -4,
55 XML_UNTERMINATED_COMMENT
= -5,
56 XML_UNTERMINATED_ELEMENT
= -6,
57 XML_OUT_OF_MEMORY
= -7,
58 XML_UNTERMINATED_ATTRIBUTE
= -8,
59 XML_MISSING_CLOSE_TAG
= -9,
60 XML_MISSING_OPEN_TAG
= -10
64 XML_LOADED_UNDEFINED
= -1,
65 XML_LOADED_FALSE
= false,
66 XML_LOADED_TRUE
= true
69 /// Create an XML object.
71 /// An XMLDocument is always user-created, so always starts with an
72 /// associated object.
73 XML_as(as_object
& object
);
75 XML_as(as_object
& object
, const std::string
& xml
);
79 /// Convert the XML object to a string
81 /// This calls XMLNode::toString after adding an xmlDecl and
84 /// @param o The ostream to write the string to.
85 /// @param encode Whether to URL encode the node values.
86 void toString(std::ostream
& o
, bool encode
) const;
88 const std::string
& getXMLDecl() const {
92 void setXMLDecl(const std::string
& xml
) {
96 const std::string
& getDocTypeDecl() const {
100 void setDocTypeDecl(const std::string
& docType
) {
101 _docTypeDecl
= docType
;
106 /// Parses an XML document into the specified XML object tree.
108 /// This reads in an XML file from disk and parses into into a memory
109 /// resident tree which can be walked through later.
111 /// Calls to this function clear any precedently parsed data.
113 void parseXML(const std::string
& xml
);
115 XMLNode_as
* createElement(const std::string
& name
);
117 XMLNode_as
* createTextNode(const std::string
& name
);
119 ParseStatus
status() const {
123 void setStatus(ParseStatus st
) {
127 LoadStatus
loaded() const {
131 void setLoaded(LoadStatus st
) {
137 typedef std::map
<std::string
, std::string
, StringNoCaseLessThan
> Attributes
;
139 void parseTag(XMLNode_as
*& node
, xml_iterator
& it
, xml_iterator end
);
141 void parseAttribute(XMLNode_as
* node
, xml_iterator
& it
,
142 xml_iterator end
, Attributes
& attributes
);
144 void parseDocTypeDecl( xml_iterator
& it
, xml_iterator end
);
146 void parseText(XMLNode_as
* node
, xml_iterator
& it
, xml_iterator end
);
148 void parseXMLDecl(xml_iterator
& it
, xml_iterator end
);
150 void parseComment(XMLNode_as
* node
, xml_iterator
& it
, xml_iterator end
);
152 void parseCData(XMLNode_as
* node
, xml_iterator
& it
, xml_iterator end
);
154 /// Clear all properties.
156 /// This removes all children, resets doctype and xml decls, and
157 /// sets status to XML.
161 /// Return true if ignoreWhite property was set to anything evaluating
165 // -1 if never asked to load anything
166 // 0 if asked to load but not yet loaded (or failure)
167 // 1 if successfully loaded
172 std::string _docTypeDecl
;
174 std::string _xmlDecl
;
179 /// Escape using XML entities.
181 /// Note this is not the same as a URL escape.
182 void escapeXML(std::string
& text
);
183 void unescapeXML(std::string
& text
);
185 /// Register the XML class.
186 void xml_class_init(as_object
& where
, const ObjectURI
& uri
);
188 /// Register XML native functions.
189 void registerXMLNative(as_object
& where
);
196 // indent-tabs-mode: t