1
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2
/* ***** BEGIN LICENSE BLOCK *****
3
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
5
* The contents of this file are subject to the Netscape Public License
6
* Version 1.1 (the "License"); you may not use this file except in
7
* compliance with the License. You may obtain a copy of the License at
8
* http://www.mozilla.org/NPL/
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.
25
* Alternatively, the contents of this file may be used under the terms of
26
* either the GNU General Public License Version 2 or later (the "GPL"), or
27
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28
* in which case the provisions of the GPL or the LGPL are applicable instead
29
* of those above. If you wish to allow use of your version of this file only
30
* under the terms of either the GPL or the LGPL, and not to allow others to
31
* use your version of this file under the terms of the NPL, indicate your
32
* decision by deleting the provisions above and replace them with the notice
33
* and other provisions required by the GPL or the LGPL. If you do not delete
34
* the provisions above, a recipient may use your version of this file under
35
* the terms of any one of the NPL, the GPL or the LGPL.
37
* ***** END LICENSE BLOCK ***** */
39
#include "nsGenericElement.h"
40
#include "nsLayoutAtoms.h"
41
#include "nsUnicharUtils.h"
42
#include "nsXMLProcessingInstruction.h"
43
#include "nsParserUtils.h"
46
NS_NewXMLProcessingInstruction(nsIContent** aInstancePtrResult,
47
const nsAString& aTarget,
48
const nsAString& aData)
50
if (aTarget.Equals(NS_LITERAL_STRING("xml-stylesheet"))) {
51
return NS_NewXMLStylesheetProcessingInstruction(aInstancePtrResult, aData);
53
*aInstancePtrResult = new nsXMLProcessingInstruction(aTarget, aData);
54
NS_ENSURE_TRUE(*aInstancePtrResult, NS_ERROR_OUT_OF_MEMORY);
56
NS_ADDREF(*aInstancePtrResult);
61
nsXMLProcessingInstruction::nsXMLProcessingInstruction(const nsAString& aTarget,
62
const nsAString& aData) :
65
nsGenericDOMDataNode::SetData(aData);
68
nsXMLProcessingInstruction::~nsXMLProcessingInstruction()
73
// QueryInterface implementation for nsXMLProcessingInstruction
74
NS_INTERFACE_MAP_BEGIN(nsXMLProcessingInstruction)
75
NS_INTERFACE_MAP_ENTRY(nsIDOMNode)
76
NS_INTERFACE_MAP_ENTRY(nsIDOMProcessingInstruction)
77
NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(ProcessingInstruction)
78
NS_INTERFACE_MAP_END_INHERITING(nsGenericDOMDataNode)
81
NS_IMPL_ADDREF_INHERITED(nsXMLProcessingInstruction, nsGenericDOMDataNode)
82
NS_IMPL_RELEASE_INHERITED(nsXMLProcessingInstruction, nsGenericDOMDataNode)
86
nsXMLProcessingInstruction::GetTarget(nsAString& aTarget)
88
aTarget.Assign(mTarget);
94
nsXMLProcessingInstruction::SetData(const nsAString& aData)
96
return SetNodeValue(aData);
100
nsXMLProcessingInstruction::GetData(nsAString& aData)
102
return nsGenericDOMDataNode::GetData(aData);
106
nsXMLProcessingInstruction::GetAttrValue(const nsAString& aAttr,
112
return nsParserUtils::GetQuotedAttributeValue(data, aAttr, aValue);
116
nsXMLProcessingInstruction::Tag() const
118
return nsLayoutAtoms::processingInstructionTagName;
122
nsXMLProcessingInstruction::IsContentOfType(PRUint32 aFlags) const
124
return !(aFlags & ~ePROCESSING_INSTRUCTION);
128
nsXMLProcessingInstruction::GetNodeName(nsAString& aNodeName)
130
aNodeName.Assign(mTarget);
135
nsXMLProcessingInstruction::GetNodeValue(nsAString& aNodeValue)
137
return nsGenericDOMDataNode::GetNodeValue(aNodeValue);
141
nsXMLProcessingInstruction::SetNodeValue(const nsAString& aNodeValue)
143
return nsGenericDOMDataNode::SetNodeValue(aNodeValue);
147
nsXMLProcessingInstruction::GetNodeType(PRUint16* aNodeType)
149
*aNodeType = (PRUint16)nsIDOMNode::PROCESSING_INSTRUCTION_NODE;
154
nsXMLProcessingInstruction::CloneNode(PRBool aDeep, nsIDOMNode** aReturn)
159
*aReturn = new nsXMLProcessingInstruction(mTarget, data);
161
return NS_ERROR_OUT_OF_MEMORY;
171
nsXMLProcessingInstruction::List(FILE* out, PRInt32 aIndent) const
173
NS_PRECONDITION(mDocument, "bad content");
176
for (index = aIndent; --index >= 0; ) fputs(" ", out);
178
fprintf(out, "Processing instruction refcount=%d<", mRefCnt.get());
181
ToCString(tmp, 0, mText.GetLength());
182
tmp.Insert(mTarget.get(), 0);
183
fputs(NS_LossyConvertUCS2toASCII(tmp).get(), out);
189
nsXMLProcessingInstruction::DumpContent(FILE* out, PRInt32 aIndent,
190
PRBool aDumpAll) const