~ubuntu-branches/ubuntu/saucy/gnash/saucy-proposed

« back to all changes in this revision

Viewing changes to libcore/asobj/flash/xml/XMLDocument_as.h

  • Committer: Bazaar Package Importer
  • Author(s): Sindhudweep Narayan Sarkar
  • Date: 2009-10-07 00:06:10 UTC
  • mfrom: (1.1.12 upstream)
  • Revision ID: james.westby@ubuntu.com-20091007000610-mj9rwqe774gizn1j
Tags: 0.8.6-0ubuntu1
new upstream release 0.8.6 (LP: #435897)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// XMLDocument_as.h:  ActionScript 3 "XMLDocument" class, for Gnash.
 
2
//
 
3
//   Copyright (C) 2009 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
#ifdef HAVE_CONFIG_H
 
24
#include "gnashconfig.h"
 
25
#endif
 
26
 
 
27
#include "LoadableObject.h"
 
28
#include "xml/XMLNode_as.h"
 
29
#include "log.h"
 
30
#include "dsodefs.h"
 
31
#include "StringPredicates.h"
 
32
 
 
33
#include <map>
 
34
#include <string>
 
35
 
 
36
 
 
37
namespace gnash {
 
38
 
 
39
// Forward declarations
 
40
class fn_call;
 
41
class URL;
 
42
class LoaderThread;
 
43
 
 
44
/// Implements XML (AS2) and flash.xml.XMLDocument (AS3) class.
 
45
//
 
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
 
49
{
 
50
public:
 
51
 
 
52
    enum ParseStatus {
 
53
            XML_OK = 0,
 
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
 
63
    };
 
64
 
 
65
    enum LoadStatus {
 
66
        XML_LOADED_UNDEFINED = -1,
 
67
        XML_LOADED_FALSE = false,
 
68
        XML_LOADED_TRUE = true
 
69
    };
 
70
 
 
71
    XMLDocument_as();
 
72
 
 
73
    XMLDocument_as(const std::string& xml);
 
74
 
 
75
    ~XMLDocument_as() {};
 
76
    
 
77
    static void init(as_object& where, const ObjectURI& uri);
 
78
    static void registerNative(as_object& where);
 
79
 
 
80
    /// Convert the XML object to a string
 
81
    //
 
82
    /// This calls XMLNode::toString after adding an xmlDecl and
 
83
    /// docTypeDecl
 
84
    //
 
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;
 
88
 
 
89
    const std::string& getXMLDecl() const {
 
90
        return _xmlDecl;
 
91
    }
 
92
 
 
93
    void setXMLDecl(const std::string& xml) {
 
94
        _xmlDecl = xml;
 
95
    }
 
96
 
 
97
    const std::string& getDocTypeDecl() const {
 
98
        return _docTypeDecl;
 
99
    }
 
100
 
 
101
    void setDocTypeDecl(const std::string& docType) {
 
102
        _docTypeDecl = docType;
 
103
    }
 
104
 
 
105
    // Methods
 
106
 
 
107
    /// Parses an XML document into the specified XML object tree.
 
108
    //
 
109
    /// This reads in an XML file from disk and parses into into a memory
 
110
    /// resident tree which can be walked through later.
 
111
    ///
 
112
    /// Calls to this function clear any precedently parsed data.
 
113
    ///
 
114
    void parseXML(const std::string& xml);
 
115
 
 
116
    /// Escape using XML entities.
 
117
    //
 
118
    /// Note this is not the same as a URL escape.
 
119
    static void escape(std::string& text);
 
120
 
 
121
    /// Unescape XML entities.
 
122
    //
 
123
    /// Note this is not the same as a URL unescape.
 
124
    static void unescape(std::string& text);
 
125
 
 
126
    XMLNode_as* createElement(const std::string& name);
 
127
 
 
128
    XMLNode_as* createTextNode(const std::string& name);
 
129
 
 
130
    ParseStatus status() const {
 
131
        return _status;
 
132
    }
 
133
 
 
134
    void setStatus(ParseStatus st) {
 
135
        _status = st;
 
136
    }
 
137
 
 
138
    LoadStatus loaded() const {
 
139
        return _loaded;
 
140
    }
 
141
 
 
142
    void setLoaded(LoadStatus st) {
 
143
        _loaded = st;
 
144
    }
 
145
 
 
146
private:
 
147
 
 
148
    typedef std::map<std::string, std::string> Entities;
 
149
 
 
150
    static const Entities& getEntities();
 
151
 
 
152
    typedef std::map<std::string, std::string, StringNoCaseLessThan> Attributes;
 
153
 
 
154
    void parseTag(XMLNode_as*& node, const std::string& xml, 
 
155
            std::string::const_iterator& it);
 
156
 
 
157
    void parseAttribute(XMLNode_as* node, const std::string& xml, 
 
158
            std::string::const_iterator& it, Attributes& attributes);
 
159
 
 
160
    void parseDocTypeDecl(const std::string& xml, 
 
161
            std::string::const_iterator& it);
 
162
 
 
163
    void parseText(XMLNode_as* node, const std::string& xml, 
 
164
            std::string::const_iterator& it);
 
165
 
 
166
    void parseXMLDecl(const std::string& xml, 
 
167
            std::string::const_iterator& it);
 
168
 
 
169
    void parseComment(XMLNode_as* node, const std::string& xml, 
 
170
            std::string::const_iterator& it);
 
171
 
 
172
    void parseCData(XMLNode_as* node, const std::string& xml, 
 
173
            std::string::const_iterator& it);
 
174
 
 
175
    /// Remove all children
 
176
    void clear();
 
177
  
 
178
    /// \brief
 
179
    /// Return true if ignoreWhite property was set to anything evaluating
 
180
    /// to true.
 
181
    bool ignoreWhite() const;
 
182
 
 
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
 
186
    LoadStatus _loaded;
 
187
 
 
188
    ParseStatus _status;        
 
189
 
 
190
    std::string _docTypeDecl;
 
191
 
 
192
    std::string _xmlDecl;
 
193
 
 
194
};
 
195
 
 
196
}       // namespace gnash
 
197
// GNASH_ASOBJ3_XMLDOCUMENT_H
 
198
#endif
 
199
 
 
200
// local Variables:
 
201
// mode: C++
 
202
// indent-tabs-mode: t
 
203
// End:
 
204