domparser.cpp00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include "domparser.h"
00022 #include "domparser.lut.h"
00023
00024 #include "kjs_dom.h"
00025 #include "kjs_window.h"
00026 #include "xml/dom_nodeimpl.h"
00027 #include "xml/dom_docimpl.h"
00028
00029 #include "html/html_documentimpl.h"
00030
00031 using DOM::DocumentImpl;
00032
00034
00035
00036
00037
00038
00039
00040
00041 using namespace KJS;
00042
00043 DEFINE_PROTOTYPE("DOMParser",DOMParserProto)
00044 IMPLEMENT_PROTOFUNC_DOM(DOMParserProtoFunc)
00045 IMPLEMENT_PROTOTYPE(DOMParserProto,DOMParserProtoFunc)
00046
00047 namespace KJS {
00048
00049 DOMParserConstructorImp::DOMParserConstructorImp(ExecState *, DOM::DocumentImpl *d)
00050 : doc(d)
00051 {
00052 }
00053
00054 bool DOMParserConstructorImp::implementsConstruct() const
00055 {
00056 return true;
00057 }
00058
00059 Object DOMParserConstructorImp::construct(ExecState *exec, const List &)
00060 {
00061 return Object(new DOMParser(exec, doc.get()));
00062 }
00063
00064 const ClassInfo DOMParser::info = { "DOMParser", 0, 0 , 0 };
00065
00066
00067 DOMParser::DOMParser(ExecState *exec, DOM::DocumentImpl *d)
00068 : DOMObject(DOMParserProto::self(exec)), doc(d)
00069 {
00070
00071 }
00072
00073
00074 Value DOMParserProtoFunc::tryCall(ExecState *exec, Object &thisObj, const List &args)
00075 {
00076 if (!thisObj.inherits(&DOMParser::info)) {
00077 Object err = Error::create(exec,TypeError);
00078 exec->setException(err);
00079 return err;
00080 }
00081
00082 DOMParser *parser = static_cast<DOMParser *>(thisObj.imp());
00083
00084 switch (id) {
00085 case DOMParser::ParseFromString:
00086 {
00087 if (args.size() != 2) {
00088 return Undefined();
00089 }
00090
00091 QString str = args[0].toString(exec).qstring();
00092 QString contentType = args[1].toString(exec).qstring().stripWhiteSpace();
00093
00094 if (contentType == "text/xml" || contentType == "application/xml" || contentType == "application/xhtml+xml") {
00095 DocumentImpl *docImpl = parser->doc->implementation()->createDocument();
00096
00097 docImpl->open();
00098 docImpl->write(str);
00099 docImpl->finishParsing();
00100 docImpl->close();
00101
00102 return getDOMNode(exec, docImpl);
00103 }
00104 }
00105 }
00106
00107 return Undefined();
00108 }
00109
00110 }
00111
00112
|