Back to index

lightning-sunbird  0.9+nobinonly
nsDOMDocumentType.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 Communicator client 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) 1998
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *
00024  * Alternatively, the contents of this file may be used under the terms of
00025  * either of the GNU General Public License Version 2 or later (the "GPL"),
00026  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00027  * in which case the provisions of the GPL or the LGPL are applicable instead
00028  * of those above. If you wish to allow use of your version of this file only
00029  * under the terms of either the GPL or the LGPL, and not to allow others to
00030  * use your version of this file under the terms of the MPL, indicate your
00031  * decision by deleting the provisions above and replace them with the notice
00032  * and other provisions required by the GPL or the LGPL. If you do not delete
00033  * the provisions above, a recipient may use your version of this file under
00034  * the terms of any one of the MPL, the GPL or the LGPL.
00035  *
00036  * ***** END LICENSE BLOCK ***** */
00037 
00038 #include "nsDOMDocumentType.h"
00039 #include "nsDOMAttributeMap.h"
00040 #include "nsIDOMNamedNodeMap.h"
00041 #include "nsLayoutAtoms.h"
00042 #include "nsCOMPtr.h"
00043 #include "nsContentUtils.h"
00044 #include "nsDOMString.h"
00045 #include "nsIDOM3Node.h"
00046 #include "nsNodeInfoManager.h"
00047 
00048 nsresult
00049 NS_NewDOMDocumentType(nsIDOMDocumentType** aDocType,
00050                       nsNodeInfoManager *aNodeInfoManager,
00051                       nsIPrincipal *aPrincipal,
00052                       nsIAtom *aName,
00053                       nsIDOMNamedNodeMap *aEntities,
00054                       nsIDOMNamedNodeMap *aNotations,
00055                       const nsAString& aPublicId,
00056                       const nsAString& aSystemId,
00057                       const nsAString& aInternalSubset)
00058 {
00059   NS_PRECONDITION(aNodeInfoManager || aPrincipal,
00060                   "Must have a principal if no nodeinfo manager.");
00061   NS_ENSURE_ARG_POINTER(aDocType);
00062   NS_ENSURE_ARG_POINTER(aName);
00063 
00064   nsresult rv;
00065 
00066   nsRefPtr<nsNodeInfoManager> nimgr;
00067   if (aNodeInfoManager) {
00068     nimgr = aNodeInfoManager;
00069   }
00070   else {
00071     nimgr = new nsNodeInfoManager();
00072     NS_ENSURE_TRUE(nimgr, NS_ERROR_OUT_OF_MEMORY);
00073     
00074     rv = nimgr->Init(nsnull);
00075     NS_ENSURE_SUCCESS(rv, rv);
00076 
00077     nimgr->SetDocumentPrincipal(aPrincipal);
00078   }
00079 
00080   *aDocType = new nsDOMDocumentType(nimgr, aName, aEntities, aNotations,
00081                                     aPublicId, aSystemId, aInternalSubset);
00082   if (!*aDocType) {
00083     return NS_ERROR_OUT_OF_MEMORY;
00084   }
00085 
00086   NS_ADDREF(*aDocType);
00087 
00088   return NS_OK;
00089 }
00090 
00091 nsDOMDocumentType::nsDOMDocumentType(nsNodeInfoManager *aNodeInfoManager,
00092                                      nsIAtom *aName,
00093                                      nsIDOMNamedNodeMap *aEntities,
00094                                      nsIDOMNamedNodeMap *aNotations,
00095                                      const nsAString& aPublicId,
00096                                      const nsAString& aSystemId,
00097                                      const nsAString& aInternalSubset) :
00098   nsGenericDOMDataNode(aNodeInfoManager),
00099   mName(aName),
00100   mEntities(aEntities),
00101   mNotations(aNotations),
00102   mPublicId(aPublicId),
00103   mSystemId(aSystemId),
00104   mInternalSubset(aInternalSubset)
00105 {
00106 }
00107 
00108 nsDOMDocumentType::~nsDOMDocumentType()
00109 {
00110 }
00111 
00112 
00113 // QueryInterface implementation for nsDOMDocumentType
00114 NS_INTERFACE_MAP_BEGIN(nsDOMDocumentType)
00115   NS_INTERFACE_MAP_ENTRY(nsIContent)
00116   NS_INTERFACE_MAP_ENTRY(nsIDOMGCParticipant)
00117   NS_INTERFACE_MAP_ENTRY(nsIDOMNode)
00118   NS_INTERFACE_MAP_ENTRY(nsIDOMDocumentType)
00119   NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIContent)
00120   NS_INTERFACE_MAP_ENTRY_TEAROFF(nsIDOM3Node, new nsNode3Tearoff(this))
00121   NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(DocumentType)
00122 NS_INTERFACE_MAP_END
00123 
00124 
00125 NS_IMPL_ADDREF(nsDOMDocumentType)
00126 NS_IMPL_RELEASE(nsDOMDocumentType)
00127 
00128 
00129 NS_IMETHODIMP    
00130 nsDOMDocumentType::GetName(nsAString& aName)
00131 {
00132   return mName->ToString(aName);
00133 }
00134 
00135 NS_IMETHODIMP    
00136 nsDOMDocumentType::GetEntities(nsIDOMNamedNodeMap** aEntities)
00137 {
00138   NS_ENSURE_ARG_POINTER(aEntities);
00139 
00140   *aEntities = mEntities;
00141 
00142   NS_IF_ADDREF(*aEntities);
00143 
00144   return NS_OK;
00145 }
00146 
00147 NS_IMETHODIMP    
00148 nsDOMDocumentType::GetNotations(nsIDOMNamedNodeMap** aNotations)
00149 {
00150   NS_ENSURE_ARG_POINTER(aNotations);
00151 
00152   *aNotations = mNotations;
00153 
00154   NS_IF_ADDREF(*aNotations);
00155 
00156   return NS_OK;
00157 }
00158 
00159 NS_IMETHODIMP
00160 nsDOMDocumentType::GetPublicId(nsAString& aPublicId)
00161 {
00162   aPublicId = mPublicId;
00163 
00164   return NS_OK;
00165 }
00166 
00167 NS_IMETHODIMP
00168 nsDOMDocumentType::GetSystemId(nsAString& aSystemId)
00169 {
00170   aSystemId = mSystemId;
00171 
00172   return NS_OK;
00173 }
00174 
00175 NS_IMETHODIMP
00176 nsDOMDocumentType::GetInternalSubset(nsAString& aInternalSubset)
00177 {
00178   // XXX: null string
00179   aInternalSubset = mInternalSubset;
00180 
00181   return NS_OK;
00182 }
00183 
00184 nsIAtom *
00185 nsDOMDocumentType::Tag() const
00186 {
00187   return mName;
00188 }
00189 
00190 NS_IMETHODIMP
00191 nsDOMDocumentType::GetNodeName(nsAString& aNodeName)
00192 {
00193   return mName->ToString(aNodeName);
00194 }
00195 
00196 NS_IMETHODIMP
00197 nsDOMDocumentType::GetNodeValue(nsAString& aNodeValue)
00198 {
00199   SetDOMStringToNull(aNodeValue);
00200 
00201   return NS_OK;
00202 }
00203 
00204 NS_IMETHODIMP
00205 nsDOMDocumentType::SetNodeValue(const nsAString& aNodeValue)
00206 {
00207   return NS_OK;
00208 }
00209 
00210 NS_IMETHODIMP
00211 nsDOMDocumentType::GetNodeType(PRUint16* aNodeType)
00212 {
00213   *aNodeType = nsIDOMNode::DOCUMENT_TYPE_NODE;
00214 
00215   return NS_OK;
00216 }
00217 
00218 NS_IMETHODIMP
00219 nsDOMDocumentType::CloneNode(PRBool aDeep, nsIDOMNode** aReturn)
00220 {
00221   nsDOMDocumentType* it = new nsDOMDocumentType(GetNodeInfoManager(), mName,
00222                                                 mEntities,
00223                                                 mNotations,
00224                                                 mPublicId,
00225                                                 mSystemId,
00226                                                 mInternalSubset);
00227   if (!it) {
00228     return NS_ERROR_OUT_OF_MEMORY;
00229   }
00230 
00231   return CallQueryInterface(it, aReturn);
00232 }