Back to index

lightning-sunbird  0.9+nobinonly
nsDOMBuilder.cpp
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
00002 /* ***** BEGIN LICENSE BLOCK *****
00003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is mozilla.org code.
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Netscape Communications Corporation.
00019  * Portions created by the Initial Developer are Copyright (C) 2002
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *      Boris Zbarsky <bzbarsky@mit.edu>  (original author)
00024  *
00025  * Alternatively, the contents of this file may be used under the terms of
00026  * either the GNU General Public License Version 2 or later (the "GPL"), or
00027  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00028  * in which case the provisions of the GPL or the LGPL are applicable instead
00029  * of those above. If you wish to allow use of your version of this file only
00030  * under the terms of either the GPL or the LGPL, and not to allow others to
00031  * use your version of this file under the terms of the MPL, indicate your
00032  * decision by deleting the provisions above and replace them with the notice
00033  * and other provisions required by the GPL or the LGPL. If you do not delete
00034  * the provisions above, a recipient may use your version of this file under
00035  * the terms of any one of the MPL, the GPL or the LGPL.
00036  *
00037  * ***** END LICENSE BLOCK ***** */
00038 
00039 #include "nsDOMBuilder.h"
00040 #include "nsDOMError.h"
00041 #include "nsContentUtils.h"  // for NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO
00042 #include "nsIDOMDocument.h"
00043 
00044 static const char kLoadAsData[] = "loadAsData";
00045 
00046 nsresult
00047 NS_NewDOMBuilder(nsIDOMDOMBuilder** aResult,
00048                  PRUint16 aMode,
00049                  const nsAString & aSchemaType,
00050                nsIDOMDOMImplementation* aDOMImplementation)
00051 {
00052   NS_PRECONDITION(aResult, "Null out ptr?  Who do you think you are, flouting XPCOM contract?");
00053   NS_PRECONDITION(aDOMImplementation, "How are we supposed to create documents without a DOMImplementation?");
00054 
00055   nsDOMBuilder* it = new nsDOMBuilder(aMode, aSchemaType, aDOMImplementation);
00056   if (!it)
00057     return NS_ERROR_OUT_OF_MEMORY;
00058 
00059   return CallQueryInterface(it, aResult);
00060 }
00061 
00062 nsDOMBuilder::nsDOMBuilder(PRUint16 aMode,
00063                         const nsAString& aSchemaType,
00064                         nsIDOMDOMImplementation* aDOMImplementation)
00065 {
00066   mDOMImplementation = aDOMImplementation;
00067 }
00068 
00069 nsDOMBuilder::~nsDOMBuilder()
00070 {
00071 }
00072 
00073 NS_IMPL_ADDREF(nsDOMBuilder)
00074 NS_IMPL_RELEASE(nsDOMBuilder)
00075 
00076 NS_INTERFACE_MAP_BEGIN(nsDOMBuilder)
00077   NS_INTERFACE_MAP_ENTRY(nsIDOMDOMBuilder)
00078   NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIDOMDOMBuilder)
00079   NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(DOMBuilder)
00080 NS_INTERFACE_MAP_END
00081 
00082 // nsIDOMDOMBuilder
00083 NS_IMETHODIMP
00084 nsDOMBuilder::GetEntityResolver(nsIDOMDOMEntityResolver** aEntityResolver)
00085 {
00086   *aEntityResolver = mEntityResolver;
00087   NS_IF_ADDREF(*aEntityResolver);
00088   return NS_OK;
00089 }
00090 
00091 NS_IMETHODIMP
00092 nsDOMBuilder::SetEntityResolver(nsIDOMDOMEntityResolver* aEntityResolver)
00093 {
00094   mEntityResolver = aEntityResolver;
00095   return NS_OK;
00096 }
00097 
00098 NS_IMETHODIMP
00099 nsDOMBuilder::GetErrorHandler(nsIDOMDOMErrorHandler** aErrorHandler)
00100 {
00101   *aErrorHandler = mErrorHandler;
00102   NS_IF_ADDREF(*aErrorHandler);
00103   return NS_OK;
00104 }
00105 
00106 NS_IMETHODIMP
00107 nsDOMBuilder::SetErrorHandler(nsIDOMDOMErrorHandler* aErrorHandler)
00108 {
00109   mErrorHandler = aErrorHandler;
00110   return NS_OK;
00111 }
00112 
00113 NS_IMETHODIMP
00114 nsDOMBuilder::GetFilter(nsIDOMDOMBuilderFilter** aFilter)
00115 {
00116   *aFilter = mFilter;
00117   NS_IF_ADDREF(*aFilter);
00118   return NS_OK;
00119 }
00120 
00121 NS_IMETHODIMP
00122 nsDOMBuilder::SetFilter(nsIDOMDOMBuilderFilter* aFilter)
00123 {
00124   mFilter = aFilter;
00125   return NS_OK;
00126 }
00127 
00128 
00129 NS_IMETHODIMP
00130 nsDOMBuilder::SetFeature(const nsAString& aName, PRBool aState)
00131 {
00132   // XXX We don't know about any features yet
00133   return NS_ERROR_DOM_NOT_FOUND_ERR;
00134 }
00135 
00136 NS_IMETHODIMP
00137 nsDOMBuilder::CanSetFeature(const nsAString& aName, PRBool aState,
00138                          PRBool* aCanSet)
00139 {
00140   // XXX We can't set anything
00141   *aCanSet = PR_FALSE;
00142   return NS_OK;
00143 }
00144 
00145 NS_IMETHODIMP
00146 nsDOMBuilder::GetFeature(const nsAString& aName, PRBool* aIsOn)
00147 {
00148   // XXX We don't know about any features yet
00149   return NS_ERROR_DOM_NOT_FOUND_ERR;
00150 }
00151     
00152 NS_IMETHODIMP
00153 nsDOMBuilder::ParseURI(const nsAString& aURI, nsIDOMDocument** aDocument)
00154 {
00155   *aDocument = nsnull;
00156 
00157   nsCOMPtr<nsIDOMDocument> domDoc;
00158 
00159   NS_NAMED_LITERAL_STRING(emptyStr, "");
00160   mDOMImplementation->CreateDocument(emptyStr,
00161                                  emptyStr,
00162                                  nsnull,
00163                                  getter_AddRefs(domDoc));
00164 
00165   if (!domDoc)
00166     return NS_ERROR_FAILURE;
00167 
00168   // XXX synchronous loading?  We'd have to do something right about now.
00169 
00170   
00171   
00172   return NS_ERROR_NOT_IMPLEMENTED;
00173 }
00174 
00175 NS_IMETHODIMP
00176 nsDOMBuilder::Parse(nsIDOMDOMInputSource* aInputSource,
00177                   nsIDOMDocument** aDocument)
00178 {
00179   *aDocument = nsnull;
00180   return NS_ERROR_NOT_IMPLEMENTED;
00181 }
00182 
00183 NS_IMETHODIMP
00184 nsDOMBuilder::ParseWithContext(nsIDOMDOMInputSource* aInputSource,
00185                             nsIDOMNode* aContextNode,
00186                             PRUint16 aAction)
00187 {
00188   return NS_ERROR_NOT_IMPLEMENTED;
00189 }