1
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2
/* ***** BEGIN LICENSE BLOCK *****
3
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
5
* The contents of this file are subject to the Mozilla Public License Version
6
* 1.1 (the "License"); you may not use this file except in compliance with
7
* the License. You may obtain a copy of the License at
8
* http://www.mozilla.org/MPL/
10
* Software distributed under the License is distributed on an "AS IS" basis,
11
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12
* for the specific language governing rights and limitations under the
15
* The Original Code is Mozilla Communicator client code.
17
* The Initial Developer of the Original Code is
18
* Netscape Communications Corporation.
19
* Portions created by the Initial Developer are Copyright (C) 1998
20
* the Initial Developer. All Rights Reserved.
24
* Alternatively, the contents of this file may be used under the terms of
25
* either of the GNU General Public License Version 2 or later (the "GPL"),
26
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27
* in which case the provisions of the GPL or the LGPL are applicable instead
28
* of those above. If you wish to allow use of your version of this file only
29
* under the terms of either the GPL or the LGPL, and not to allow others to
30
* use your version of this file under the terms of the MPL, indicate your
31
* decision by deleting the provisions above and replace them with the notice
32
* and other provisions required by the GPL or the LGPL. If you do not delete
33
* the provisions above, a recipient may use your version of this file under
34
* the terms of any one of the MPL, the GPL or the LGPL.
36
* ***** END LICENSE BLOCK ***** */
38
#include "nsIDOMCDATASection.h"
39
#include "nsGenericDOMDataNode.h"
40
#include "nsGkAtoms.h"
41
#include "nsIDocument.h"
42
#include "nsContentUtils.h"
45
class nsXMLCDATASection : public nsGenericDOMDataNode,
46
public nsIDOMCDATASection
49
nsXMLCDATASection(nsINodeInfo *aNodeInfo);
50
virtual ~nsXMLCDATASection();
53
NS_DECL_ISUPPORTS_INHERITED
56
NS_IMPL_NSIDOMNODE_USING_GENERIC_DOM_DATA
58
// nsIDOMCharacterData
59
NS_FORWARD_NSIDOMCHARACTERDATA(nsGenericDOMDataNode::)
62
NS_FORWARD_NSIDOMTEXT(nsGenericDOMDataNode::)
68
virtual PRBool IsNodeOfType(PRUint32 aFlags) const;
70
virtual void List(FILE* out, PRInt32 aIndent) const;
71
virtual void DumpContent(FILE* out, PRInt32 aIndent,PRBool aDumpAll) const;
76
NS_NewXMLCDATASection(nsIContent** aInstancePtrResult,
77
nsNodeInfoManager *aNodeInfoManager)
79
NS_PRECONDITION(aNodeInfoManager, "Missing nodeinfo manager");
81
*aInstancePtrResult = nsnull;
83
nsCOMPtr<nsINodeInfo> ni;
84
nsresult rv = aNodeInfoManager->GetNodeInfo(nsGkAtoms::cdataTagName,
85
nsnull, kNameSpaceID_None,
87
NS_ENSURE_SUCCESS(rv, rv);
89
nsXMLCDATASection *instance = new (ni) nsXMLCDATASection(ni);
91
return NS_ERROR_OUT_OF_MEMORY;
94
NS_ADDREF(*aInstancePtrResult = instance);
99
nsXMLCDATASection::nsXMLCDATASection(nsINodeInfo *aNodeInfo)
100
: nsGenericDOMDataNode(aNodeInfo)
104
nsXMLCDATASection::~nsXMLCDATASection()
109
// QueryInterface implementation for nsXMLCDATASection
110
NS_INTERFACE_MAP_BEGIN(nsXMLCDATASection)
111
NS_INTERFACE_MAP_ENTRY(nsIDOMNode)
112
NS_INTERFACE_MAP_ENTRY(nsIDOMCharacterData)
113
NS_INTERFACE_MAP_ENTRY(nsIDOMText)
114
NS_INTERFACE_MAP_ENTRY(nsIDOMCDATASection)
115
NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(CDATASection)
116
NS_INTERFACE_MAP_END_INHERITING(nsGenericDOMDataNode)
118
NS_IMPL_ADDREF_INHERITED(nsXMLCDATASection, nsGenericDOMDataNode)
119
NS_IMPL_RELEASE_INHERITED(nsXMLCDATASection, nsGenericDOMDataNode)
123
nsXMLCDATASection::IsNodeOfType(PRUint32 aFlags) const
125
return !(aFlags & ~(eCONTENT | eTEXT | eDATA_NODE));
129
nsXMLCDATASection::GetNodeName(nsAString& aNodeName)
131
aNodeName.AssignLiteral("#cdata-section");
136
nsXMLCDATASection::GetNodeValue(nsAString& aNodeValue)
138
return nsGenericDOMDataNode::GetNodeValue(aNodeValue);
142
nsXMLCDATASection::SetNodeValue(const nsAString& aNodeValue)
144
return nsGenericDOMDataNode::SetNodeValue(aNodeValue);
148
nsXMLCDATASection::GetNodeType(PRUint16* aNodeType)
150
*aNodeType = (PRUint16)nsIDOMNode::CDATA_SECTION_NODE;
154
nsGenericDOMDataNode*
155
nsXMLCDATASection::CloneDataNode(nsINodeInfo *aNodeInfo, PRBool aCloneText) const
157
nsXMLCDATASection *it = new (aNodeInfo) nsXMLCDATASection(aNodeInfo);
158
if (it && aCloneText) {
167
nsXMLCDATASection::List(FILE* out, PRInt32 aIndent) const
170
for (index = aIndent; --index >= 0; ) fputs(" ", out);
172
fprintf(out, "CDATASection refcount=%d<", mRefCnt.get());
175
ToCString(tmp, 0, mText.GetLength());
176
fputs(NS_LossyConvertUTF16toASCII(tmp).get(), out);
182
nsXMLCDATASection::DumpContent(FILE* out, PRInt32 aIndent,
183
PRBool aDumpAll) const {