Gnash 0.8.9
|
00001 // XML_as.h: ActionScript 3 "XMLDocument" class, for Gnash. 00002 // 00003 // Copyright (C) 2009, 2010, 2011 Free Software Foundation, Inc. 00004 // 00005 // This program is free software; you can redistribute it and/or modify 00006 // it under the terms of the GNU General Public License as published by 00007 // the Free Software Foundation; either version 3 of the License, or 00008 // (at your option) any later version. 00009 // 00010 // This program is distributed in the hope that it will be useful, 00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 // GNU General Public License for more details. 00014 // 00015 // You should have received a copy of the GNU General Public License 00016 // along with this program; if not, write to the Free Software 00017 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 00018 // 00019 00020 #ifndef GNASH_ASOBJ3_XMLDOCUMENT_H 00021 #define GNASH_ASOBJ3_XMLDOCUMENT_H 00022 00023 #include "XMLNode_as.h" 00024 #include "dsodefs.h" 00025 #include "StringPredicates.h" 00026 00027 #include <map> 00028 #include <string> 00029 00030 00031 namespace gnash { 00032 00033 // Forward declarations 00034 class fn_call; 00035 class URL; 00036 00038 // 00041 // 00044 class XML_as : public XMLNode_as 00045 { 00046 public: 00047 00048 typedef std::string::const_iterator xml_iterator; 00049 00050 enum ParseStatus { 00051 XML_OK = 0, 00052 XML_UNTERMINATED_CDATA = -2, 00053 XML_UNTERMINATED_XML_DECL = -3, 00054 XML_UNTERMINATED_DOCTYPE_DECL = -4, 00055 XML_UNTERMINATED_COMMENT = -5, 00056 XML_UNTERMINATED_ELEMENT = -6, 00057 XML_OUT_OF_MEMORY = -7, 00058 XML_UNTERMINATED_ATTRIBUTE = -8, 00059 XML_MISSING_CLOSE_TAG = -9, 00060 XML_MISSING_OPEN_TAG = -10 00061 }; 00062 00063 enum LoadStatus { 00064 XML_LOADED_UNDEFINED = -1, 00065 XML_LOADED_FALSE = false, 00066 XML_LOADED_TRUE = true 00067 }; 00068 00070 // 00073 XML_as(as_object& object); 00074 00075 XML_as(as_object& object, const std::string& xml); 00076 00077 ~XML_as() {}; 00078 00080 // 00083 // 00086 void toString(std::ostream& o, bool encode) const; 00087 00088 const std::string& getXMLDecl() const { 00089 return _xmlDecl; 00090 } 00091 00092 void setXMLDecl(const std::string& xml) { 00093 _xmlDecl = xml; 00094 } 00095 00096 const std::string& getDocTypeDecl() const { 00097 return _docTypeDecl; 00098 } 00099 00100 void setDocTypeDecl(const std::string& docType) { 00101 _docTypeDecl = docType; 00102 } 00103 00104 // Methods 00105 00107 // 00113 void parseXML(const std::string& xml); 00114 00115 XMLNode_as* createElement(const std::string& name); 00116 00117 XMLNode_as* createTextNode(const std::string& name); 00118 00119 ParseStatus status() const { 00120 return _status; 00121 } 00122 00123 void setStatus(ParseStatus st) { 00124 _status = st; 00125 } 00126 00127 LoadStatus loaded() const { 00128 return _loaded; 00129 } 00130 00131 void setLoaded(LoadStatus st) { 00132 _loaded = st; 00133 } 00134 00135 private: 00136 00137 typedef std::map<std::string, std::string, StringNoCaseLessThan> Attributes; 00138 00139 void parseTag(XMLNode_as*& node, xml_iterator& it, xml_iterator end); 00140 00141 void parseAttribute(XMLNode_as* node, xml_iterator& it, 00142 xml_iterator end, Attributes& attributes); 00143 00144 void parseDocTypeDecl( xml_iterator& it, xml_iterator end); 00145 00146 void parseText(XMLNode_as* node, xml_iterator& it, xml_iterator end); 00147 00148 void parseXMLDecl(xml_iterator& it, xml_iterator end); 00149 00150 void parseComment(XMLNode_as* node, xml_iterator& it, xml_iterator end); 00151 00152 void parseCData(XMLNode_as* node, xml_iterator& it, xml_iterator end); 00153 00155 // 00158 void clear(); 00159 00163 bool ignoreWhite(); 00164 00165 // -1 if never asked to load anything 00166 // 0 if asked to load but not yet loaded (or failure) 00167 // 1 if successfully loaded 00168 LoadStatus _loaded; 00169 00170 ParseStatus _status; 00171 00172 std::string _docTypeDecl; 00173 00174 std::string _xmlDecl; 00175 00176 }; 00177 00178 00180 // 00182 void escapeXML(std::string& text); 00183 void unescapeXML(std::string& text); 00184 00186 void xml_class_init(as_object& where, const ObjectURI& uri); 00187 00189 void registerXMLNative(as_object& where); 00190 00191 } // namespace gnash 00192 #endif 00193 00194 // local Variables: 00195 // mode: C++ 00196 // indent-tabs-mode: t 00197 // End: 00198