Back to index

lightning-sunbird  0.9+nobinonly
nsXMLCDATASection.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 "nsIDOMCDATASection.h"
00039 #include "nsGenericDOMDataNode.h"
00040 #include "nsLayoutAtoms.h"
00041 #include "nsIDocument.h"
00042 #include "nsContentUtils.h"
00043 
00044 
00045 class nsXMLCDATASection : public nsGenericDOMDataNode,
00046                           public nsIDOMCDATASection
00047 {
00048 public:
00049   nsXMLCDATASection(nsNodeInfoManager *aNodeInfoManager);
00050   virtual ~nsXMLCDATASection();
00051 
00052   // nsISupports
00053   NS_DECL_ISUPPORTS_INHERITED
00054 
00055   // nsIDOMNode
00056   NS_IMPL_NSIDOMNODE_USING_GENERIC_DOM_DATA
00057 
00058   // nsIDOMCharacterData
00059   NS_FORWARD_NSIDOMCHARACTERDATA(nsGenericDOMDataNode::)
00060 
00061   // nsIDOMText
00062   NS_FORWARD_NSIDOMTEXT(nsGenericDOMDataNode::)
00063 
00064   // nsIDOMCDATASection
00065   // Empty interface
00066 
00067   // nsIContent
00068   virtual nsIAtom *Tag() const;
00069   virtual PRBool IsContentOfType(PRUint32 aFlags) const;
00070 #ifdef DEBUG
00071   virtual void List(FILE* out, PRInt32 aIndent) const;
00072   virtual void DumpContent(FILE* out, PRInt32 aIndent,PRBool aDumpAll) const;
00073 #endif
00074 
00075   virtual already_AddRefed<nsITextContent> CloneContent(PRBool aCloneText,
00076                                                         nsNodeInfoManager *aNodeInfoManager);
00077 
00078 protected:
00079 };
00080 
00081 nsresult
00082 NS_NewXMLCDATASection(nsIContent** aInstancePtrResult,
00083                       nsNodeInfoManager *aNodeInfoManager)
00084 {
00085   NS_PRECONDITION(aNodeInfoManager, "Missing nodeinfo manager");
00086 
00087   *aInstancePtrResult = nsnull;
00088 
00089   nsXMLCDATASection *instance = new nsXMLCDATASection(aNodeInfoManager);
00090   if (!instance) {
00091     return NS_ERROR_OUT_OF_MEMORY;
00092   }
00093 
00094   NS_ADDREF(*aInstancePtrResult = instance);
00095 
00096   return NS_OK;
00097 }
00098 
00099 nsXMLCDATASection::nsXMLCDATASection(nsNodeInfoManager *aNodeInfoManager)
00100   : nsGenericDOMDataNode(aNodeInfoManager)
00101 {
00102 }
00103 
00104 nsXMLCDATASection::~nsXMLCDATASection()
00105 {
00106 }
00107 
00108 
00109 // QueryInterface implementation for nsXMLCDATASection
00110 NS_INTERFACE_MAP_BEGIN(nsXMLCDATASection)
00111   NS_INTERFACE_MAP_ENTRY(nsITextContent)
00112   NS_INTERFACE_MAP_ENTRY(nsIDOMNode)
00113   NS_INTERFACE_MAP_ENTRY(nsIDOMCharacterData)
00114   NS_INTERFACE_MAP_ENTRY(nsIDOMText)
00115   NS_INTERFACE_MAP_ENTRY(nsIDOMCDATASection)
00116   NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(CDATASection)
00117 NS_INTERFACE_MAP_END_INHERITING(nsGenericDOMDataNode)
00118 
00119 NS_IMPL_ADDREF_INHERITED(nsXMLCDATASection, nsGenericDOMDataNode)
00120 NS_IMPL_RELEASE_INHERITED(nsXMLCDATASection, nsGenericDOMDataNode)
00121 
00122 
00123 nsIAtom *
00124 nsXMLCDATASection::Tag() const
00125 {
00126   return nsLayoutAtoms::cdataTagName;
00127 }
00128 
00129 PRBool
00130 nsXMLCDATASection::IsContentOfType(PRUint32 aFlags) const
00131 {
00132   return !(aFlags & ~eTEXT);
00133 }
00134 
00135 NS_IMETHODIMP
00136 nsXMLCDATASection::GetNodeName(nsAString& aNodeName)
00137 {
00138   aNodeName.AssignLiteral("#cdata-section");
00139   return NS_OK;
00140 }
00141 
00142 NS_IMETHODIMP
00143 nsXMLCDATASection::GetNodeValue(nsAString& aNodeValue)
00144 {
00145   return nsGenericDOMDataNode::GetNodeValue(aNodeValue);
00146 }
00147 
00148 NS_IMETHODIMP
00149 nsXMLCDATASection::SetNodeValue(const nsAString& aNodeValue)
00150 {
00151   return nsGenericDOMDataNode::SetNodeValue(aNodeValue);
00152 }
00153 
00154 NS_IMETHODIMP
00155 nsXMLCDATASection::GetNodeType(PRUint16* aNodeType)
00156 {
00157   *aNodeType = (PRUint16)nsIDOMNode::CDATA_SECTION_NODE;
00158   return NS_OK;
00159 }
00160 
00161 NS_IMETHODIMP
00162 nsXMLCDATASection::CloneNode(PRBool aDeep, nsIDOMNode** aReturn)
00163 {
00164   nsCOMPtr<nsITextContent> textContent = CloneContent(PR_TRUE, GetNodeInfoManager());
00165   NS_ENSURE_TRUE(textContent, NS_ERROR_OUT_OF_MEMORY);
00166 
00167   return CallQueryInterface(textContent, aReturn);
00168 }
00169 
00170 already_AddRefed<nsITextContent> 
00171 nsXMLCDATASection::CloneContent(PRBool aCloneText, nsNodeInfoManager *aNodeInfoManager)
00172 {
00173   nsXMLCDATASection* it = new nsXMLCDATASection(aNodeInfoManager);
00174   if (!it)
00175     return nsnull;
00176 
00177   if (aCloneText) {
00178     it->mText = mText;
00179   }
00180 
00181   NS_ADDREF(it);
00182 
00183   return it;
00184 }
00185 
00186 #ifdef DEBUG
00187 void
00188 nsXMLCDATASection::List(FILE* out, PRInt32 aIndent) const
00189 {
00190   NS_PRECONDITION(IsInDoc(), "bad content");
00191 
00192   PRInt32 index;
00193   for (index = aIndent; --index >= 0; ) fputs("  ", out);
00194 
00195   fprintf(out, "CDATASection refcount=%d<", mRefCnt.get());
00196 
00197   nsAutoString tmp;
00198   ToCString(tmp, 0, mText.GetLength());
00199   fputs(NS_LossyConvertUCS2toASCII(tmp).get(), out);
00200 
00201   fputs(">\n", out);
00202 }
00203 
00204 void
00205 nsXMLCDATASection::DumpContent(FILE* out, PRInt32 aIndent,
00206                                PRBool aDumpAll) const {
00207 }
00208 #endif