khtml Library API Documentation

xmlserializer.cpp

00001 // -*- c-basic-offset: 2 -*- 00002 /* 00003 * This file is part of the KDE libraries 00004 * Copyright (C) 2003 Apple Computer, Inc. 00005 * 00006 * This library is free software; you can redistribute it and/or 00007 * modify it under the terms of the GNU Lesser General Public 00008 * License as published by the Free Software Foundation; either 00009 * version 2 of the License, or (at your option) any later version. 00010 * 00011 * This library is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00014 * Lesser General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU Lesser General Public 00017 * License along with this library; if not, write to the Free Software 00018 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00019 */ 00020 00021 #include "xmlserializer.h" 00022 #include "xmlserializer.lut.h" 00023 00024 #include "dom/dom_exception.h" 00025 #include "dom/dom_doc.h" 00026 #include "xml/dom_docimpl.h" 00027 00028 #include <kdebug.h> 00029 00030 using namespace KJS; 00031 00033 00034 /* Source for XMLSerializerProtoTable. 00035 @begin XMLSerializerProtoTable 1 00036 serializeToString XMLSerializer::SerializeToString DontDelete|Function 1 00037 @end 00038 */ 00039 DEFINE_PROTOTYPE("XMLSerializer",XMLSerializerProto) 00040 IMPLEMENT_PROTOFUNC_DOM(XMLSerializerProtoFunc) 00041 IMPLEMENT_PROTOTYPE(XMLSerializerProto,XMLSerializerProtoFunc) 00042 00043 namespace KJS { 00044 00045 XMLSerializerConstructorImp::XMLSerializerConstructorImp(ExecState *) 00046 : ObjectImp() 00047 { 00048 } 00049 00050 bool XMLSerializerConstructorImp::implementsConstruct() const 00051 { 00052 return true; 00053 } 00054 00055 Object XMLSerializerConstructorImp::construct(ExecState *exec, const List &) 00056 { 00057 return Object(new XMLSerializer(exec)); 00058 } 00059 00060 const ClassInfo XMLSerializer::info = { "XMLSerializer", 0, &XMLSerializerTable, 0 }; 00061 00062 /* Source for XMLSerializerTable. 00063 @begin XMLSerializerTable 0 00064 @end 00065 */ 00066 00067 XMLSerializer::XMLSerializer(ExecState *exec) 00068 : DOMObject(XMLSerializerProto::self(exec)) 00069 { 00070 } 00071 00072 Value XMLSerializerProtoFunc::tryCall(ExecState *exec, Object &thisObj, const List &args) 00073 { 00074 if (!thisObj.inherits(&XMLSerializer::info)) { 00075 Object err = Error::create(exec,TypeError); 00076 exec->setException(err); 00077 return err; 00078 } 00079 00080 switch (id) { 00081 case XMLSerializer::SerializeToString: 00082 { 00083 if (args.size() != 1) { 00084 return Undefined(); 00085 } 00086 00087 if (!args[0].toObject(exec).inherits(&DOMDocument::info)) { 00088 return Undefined(); 00089 } 00090 00091 DOM::Node docNode = static_cast<KJS::DOMDocument *>(args[0].toObject(exec).imp())->toNode(); 00092 DOM::DocumentImpl *doc = static_cast<DOM::DocumentImpl *>(docNode.handle()); 00093 00094 if (!doc) { 00095 return Undefined(); 00096 } 00097 00098 QString body; 00099 00100 try { 00101 body = doc->toString().string(); 00102 } catch(DOM::DOMException& e) { 00103 Object err = Error::create(exec, GeneralError, "Exception serializing document"); 00104 exec->setException(err); 00105 return err; 00106 } 00107 00108 return getString(body); 00109 } 00110 } 00111 00112 return Undefined(); 00113 } 00114 00115 } // end namespace
KDE Logo
This file is part of the documentation for khtml Library Version 3.3.0.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Wed Sep 29 09:42:30 2004 by doxygen 1.3.8 written by Dimitri van Heesch, © 1997-2003