Gnash
0.8.10
|
00001 // XML_as.h: ActionScript 3 "XMLDocument" class, for Gnash. 00002 // 00003 // Copyright (C) 2009, 2010, 2011, 2012 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 const std::string& getContentType() const { 00105 return _contentType; 00106 } 00107 00108 void setContentType(const std::string& contentType) { 00109 _contentType = contentType; 00110 } 00111 00112 // Methods 00113 00115 // 00121 void parseXML(const std::string& xml); 00122 00123 ParseStatus status() const { 00124 return _status; 00125 } 00126 00127 void setStatus(ParseStatus st) { 00128 _status = st; 00129 } 00130 00131 LoadStatus loaded() const { 00132 return _loaded; 00133 } 00134 00135 void setLoaded(LoadStatus st) { 00136 _loaded = st; 00137 } 00138 00140 bool ignoreWhite() const { 00141 return _ignoreWhite; 00142 } 00143 00145 void ignoreWhite(bool ignore) { 00146 _ignoreWhite = ignore; 00147 } 00148 00149 private: 00150 00151 typedef std::map<std::string, std::string, StringNoCaseLessThan> Attributes; 00152 00153 void parseTag(XMLNode_as*& node, xml_iterator& it, xml_iterator end); 00154 00155 void parseAttribute(XMLNode_as* node, xml_iterator& it, 00156 xml_iterator end, Attributes& attributes); 00157 00158 void parseDocTypeDecl( xml_iterator& it, xml_iterator end); 00159 00160 void parseText(XMLNode_as* node, xml_iterator& it, xml_iterator end, 00161 bool ignoreWhite); 00162 00163 void parseXMLDecl(xml_iterator& it, xml_iterator end); 00164 00165 void parseComment(XMLNode_as* node, xml_iterator& it, xml_iterator end); 00166 00167 void parseCData(XMLNode_as* node, xml_iterator& it, xml_iterator end); 00168 00170 // 00173 void clear(); 00174 00175 // -1 if never asked to load anything 00176 // 0 if asked to load but not yet loaded (or failure) 00177 // 1 if successfully loaded 00178 LoadStatus _loaded; 00179 00180 ParseStatus _status; 00181 00182 std::string _docTypeDecl; 00183 00184 std::string _xmlDecl; 00185 00186 std::string _contentType; 00187 00188 bool _ignoreWhite; 00189 }; 00190 00191 00193 // 00195 void escapeXML(std::string& text); 00196 void unescapeXML(std::string& text); 00197 00199 void xml_class_init(as_object& where, const ObjectURI& uri); 00200 00202 void registerXMLNative(as_object& where); 00203 00204 } // namespace gnash 00205 #endif 00206 00207 // local Variables: 00208 // mode: C++ 00209 // indent-tabs-mode: t 00210 // End: 00211