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 "nsGenericElement.h"
39
#include "nsGkAtoms.h"
40
#include "nsUnicharUtils.h"
41
#include "nsXMLProcessingInstruction.h"
42
#include "nsParserUtils.h"
43
#include "nsContentCreatorFunctions.h"
46
NS_NewXMLProcessingInstruction(nsIContent** aInstancePtrResult,
47
nsNodeInfoManager *aNodeInfoManager,
48
const nsAString& aTarget,
49
const nsAString& aData)
51
NS_PRECONDITION(aNodeInfoManager, "Missing nodeinfo manager");
53
if (aTarget.EqualsLiteral("xml-stylesheet")) {
54
return NS_NewXMLStylesheetProcessingInstruction(aInstancePtrResult,
55
aNodeInfoManager, aData);
58
*aInstancePtrResult = nsnull;
60
nsCOMPtr<nsINodeInfo> ni;
62
aNodeInfoManager->GetNodeInfo(nsGkAtoms::processingInstructionTagName,
63
nsnull, kNameSpaceID_None,
65
NS_ENSURE_SUCCESS(rv, rv);
67
nsXMLProcessingInstruction *instance =
68
new (ni) nsXMLProcessingInstruction(ni, aTarget, aData);
70
return NS_ERROR_OUT_OF_MEMORY;
73
NS_ADDREF(*aInstancePtrResult = instance);
78
nsXMLProcessingInstruction::nsXMLProcessingInstruction(nsINodeInfo *aNodeInfo,
79
const nsAString& aTarget,
80
const nsAString& aData)
81
: nsGenericDOMDataNode(aNodeInfo),
84
nsGenericDOMDataNode::SetData(aData);
87
nsXMLProcessingInstruction::~nsXMLProcessingInstruction()
92
// QueryInterface implementation for nsXMLProcessingInstruction
93
NS_INTERFACE_MAP_BEGIN(nsXMLProcessingInstruction)
94
NS_INTERFACE_MAP_ENTRY(nsIDOMNode)
95
NS_INTERFACE_MAP_ENTRY(nsIDOMProcessingInstruction)
96
NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(ProcessingInstruction)
97
NS_INTERFACE_MAP_END_INHERITING(nsGenericDOMDataNode)
100
NS_IMPL_ADDREF_INHERITED(nsXMLProcessingInstruction, nsGenericDOMDataNode)
101
NS_IMPL_RELEASE_INHERITED(nsXMLProcessingInstruction, nsGenericDOMDataNode)
105
nsXMLProcessingInstruction::GetTarget(nsAString& aTarget)
107
aTarget.Assign(mTarget);
113
nsXMLProcessingInstruction::SetData(const nsAString& aData)
115
return SetNodeValue(aData);
119
nsXMLProcessingInstruction::GetData(nsAString& aData)
121
return nsGenericDOMDataNode::GetData(aData);
125
nsXMLProcessingInstruction::GetAttrValue(nsIAtom *aName, nsAString& aValue)
130
return nsParserUtils::GetQuotedAttributeValue(data, aName, aValue);
134
nsXMLProcessingInstruction::IsNodeOfType(PRUint32 aFlags) const
136
return !(aFlags & ~(eCONTENT | ePROCESSING_INSTRUCTION | eDATA_NODE));
141
nsXMLProcessingInstruction::MayHaveFrame() const
147
nsXMLProcessingInstruction::GetNodeName(nsAString& aNodeName)
149
aNodeName.Assign(mTarget);
154
nsXMLProcessingInstruction::GetNodeValue(nsAString& aNodeValue)
156
return nsGenericDOMDataNode::GetNodeValue(aNodeValue);
160
nsXMLProcessingInstruction::SetNodeValue(const nsAString& aNodeValue)
162
return nsGenericDOMDataNode::SetNodeValue(aNodeValue);
166
nsXMLProcessingInstruction::GetNodeType(PRUint16* aNodeType)
168
*aNodeType = (PRUint16)nsIDOMNode::PROCESSING_INSTRUCTION_NODE;
172
nsGenericDOMDataNode*
173
nsXMLProcessingInstruction::CloneDataNode(nsINodeInfo *aNodeInfo,
174
PRBool aCloneText) const
177
nsGenericDOMDataNode::GetData(data);
179
return new (aNodeInfo) nsXMLProcessingInstruction(aNodeInfo, mTarget, data);
184
nsXMLProcessingInstruction::List(FILE* out, PRInt32 aIndent) const
187
for (index = aIndent; --index >= 0; ) fputs(" ", out);
189
fprintf(out, "Processing instruction refcount=%d<", mRefCnt.get());
192
ToCString(tmp, 0, mText.GetLength());
193
tmp.Insert(mTarget.get(), 0);
194
fputs(NS_LossyConvertUTF16toASCII(tmp).get(), out);
200
nsXMLProcessingInstruction::DumpContent(FILE* out, PRInt32 aIndent,
201
PRBool aDumpAll) const