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
4 : *
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/
9 : *
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
13 : * License.
14 : *
15 : * The Original Code is Mozilla Communicator client code.
16 : *
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.
21 : *
22 : * Contributor(s):
23 : *
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.
35 : *
36 : * ***** END LICENSE BLOCK ***** */
37 :
38 : #include "nsGenericElement.h"
39 : #include "nsGkAtoms.h"
40 : #include "nsUnicharUtils.h"
41 : #include "nsXMLProcessingInstruction.h"
42 : #include "nsContentCreatorFunctions.h"
43 : #include "nsContentUtils.h"
44 :
45 : nsresult
46 113 : NS_NewXMLProcessingInstruction(nsIContent** aInstancePtrResult,
47 : nsNodeInfoManager *aNodeInfoManager,
48 : const nsAString& aTarget,
49 : const nsAString& aData)
50 : {
51 113 : NS_PRECONDITION(aNodeInfoManager, "Missing nodeinfo manager");
52 :
53 226 : nsCOMPtr<nsIAtom> target = do_GetAtom(aTarget);
54 113 : NS_ENSURE_TRUE(target, NS_ERROR_OUT_OF_MEMORY);
55 :
56 113 : if (target == nsGkAtoms::xml_stylesheet) {
57 : return NS_NewXMLStylesheetProcessingInstruction(aInstancePtrResult,
58 62 : aNodeInfoManager, aData);
59 : }
60 :
61 51 : *aInstancePtrResult = nsnull;
62 :
63 102 : nsCOMPtr<nsINodeInfo> ni;
64 : ni = aNodeInfoManager->GetNodeInfo(nsGkAtoms::processingInstructionTagName,
65 : nsnull, kNameSpaceID_None,
66 : nsIDOMNode::PROCESSING_INSTRUCTION_NODE,
67 51 : target);
68 51 : NS_ENSURE_TRUE(ni, NS_ERROR_OUT_OF_MEMORY);
69 :
70 : nsXMLProcessingInstruction *instance =
71 102 : new nsXMLProcessingInstruction(ni.forget(), aData);
72 51 : if (!instance) {
73 0 : return NS_ERROR_OUT_OF_MEMORY;
74 : }
75 :
76 51 : NS_ADDREF(*aInstancePtrResult = instance);
77 :
78 51 : return NS_OK;
79 : }
80 :
81 148 : nsXMLProcessingInstruction::nsXMLProcessingInstruction(already_AddRefed<nsINodeInfo> aNodeInfo,
82 : const nsAString& aData)
83 148 : : nsGenericDOMDataNode(aNodeInfo)
84 : {
85 148 : NS_ABORT_IF_FALSE(mNodeInfo->NodeType() ==
86 : nsIDOMNode::PROCESSING_INSTRUCTION_NODE,
87 : "Bad NodeType in aNodeInfo");
88 :
89 : SetTextInternal(0, mText.GetLength(),
90 : aData.BeginReading(), aData.Length(),
91 148 : false); // Don't notify (bug 420429).
92 148 : }
93 :
94 234 : nsXMLProcessingInstruction::~nsXMLProcessingInstruction()
95 : {
96 468 : }
97 :
98 :
99 10 : DOMCI_NODE_DATA(ProcessingInstruction, nsXMLProcessingInstruction)
100 :
101 : // QueryInterface implementation for nsXMLProcessingInstruction
102 3267 : NS_INTERFACE_TABLE_HEAD(nsXMLProcessingInstruction)
103 : NS_NODE_OFFSET_AND_INTERFACE_TABLE_BEGIN(nsXMLProcessingInstruction)
104 : NS_INTERFACE_TABLE_ENTRY(nsXMLProcessingInstruction, nsIDOMNode)
105 : NS_INTERFACE_TABLE_ENTRY(nsXMLProcessingInstruction, nsIDOMCharacterData)
106 : NS_INTERFACE_TABLE_ENTRY(nsXMLProcessingInstruction,
107 : nsIDOMProcessingInstruction)
108 3267 : NS_OFFSET_AND_INTERFACE_TABLE_END
109 3236 : NS_OFFSET_AND_INTERFACE_TABLE_TO_MAP_SEGUE
110 3002 : NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(ProcessingInstruction)
111 2981 : NS_INTERFACE_MAP_END_INHERITING(nsGenericDOMDataNode)
112 :
113 :
114 1417 : NS_IMPL_ADDREF_INHERITED(nsXMLProcessingInstruction, nsGenericDOMDataNode)
115 1417 : NS_IMPL_RELEASE_INHERITED(nsXMLProcessingInstruction, nsGenericDOMDataNode)
116 :
117 :
118 : NS_IMETHODIMP
119 12 : nsXMLProcessingInstruction::GetTarget(nsAString& aTarget)
120 : {
121 12 : aTarget = NodeName();
122 :
123 12 : return NS_OK;
124 : }
125 :
126 : bool
127 0 : nsXMLProcessingInstruction::GetAttrValue(nsIAtom *aName, nsAString& aValue)
128 : {
129 0 : nsAutoString data;
130 :
131 0 : GetData(data);
132 0 : return nsContentUtils::GetPseudoAttributeValue(data, aName, aValue);
133 : }
134 :
135 : bool
136 459 : nsXMLProcessingInstruction::IsNodeOfType(PRUint32 aFlags) const
137 : {
138 459 : return !(aFlags & ~(eCONTENT | ePROCESSING_INSTRUCTION | eDATA_NODE));
139 : }
140 :
141 : nsGenericDOMDataNode*
142 35 : nsXMLProcessingInstruction::CloneDataNode(nsINodeInfo *aNodeInfo,
143 : bool aCloneText) const
144 : {
145 70 : nsAutoString data;
146 35 : nsGenericDOMDataNode::GetData(data);
147 70 : nsCOMPtr<nsINodeInfo> ni = aNodeInfo;
148 70 : return new nsXMLProcessingInstruction(ni.forget(), data);
149 : }
150 :
151 : #ifdef DEBUG
152 : void
153 0 : nsXMLProcessingInstruction::List(FILE* out, PRInt32 aIndent) const
154 : {
155 : PRInt32 index;
156 0 : for (index = aIndent; --index >= 0; ) fputs(" ", out);
157 :
158 0 : fprintf(out, "Processing instruction refcount=%d<", mRefCnt.get());
159 :
160 0 : nsAutoString tmp;
161 0 : ToCString(tmp, 0, mText.GetLength());
162 0 : tmp.Insert(nsDependentAtomString(NodeInfo()->GetExtraName()).get(), 0);
163 0 : fputs(NS_LossyConvertUTF16toASCII(tmp).get(), out);
164 :
165 0 : fputs(">\n", out);
166 0 : }
167 :
168 : void
169 0 : nsXMLProcessingInstruction::DumpContent(FILE* out, PRInt32 aIndent,
170 : bool aDumpAll) const
171 : {
172 0 : }
173 : #endif
|