~ubuntu-branches/ubuntu/precise/kompozer/precise

« back to all changes in this revision

Viewing changes to mozilla/content/xml/content/src/nsXMLProcessingInstruction.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Anthony Yarusso
  • Date: 2007-08-27 01:11:03 UTC
  • Revision ID: james.westby@ubuntu.com-20070827011103-2jgf4s6532gqu2ka
Tags: upstream-0.7.10
ImportĀ upstreamĀ versionĀ 0.7.10

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 
4
 *
 
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/
 
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
 *
 
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.
 
36
 *
 
37
 * ***** END LICENSE BLOCK ***** */
 
38
 
 
39
#include "nsGenericElement.h"
 
40
#include "nsLayoutAtoms.h"
 
41
#include "nsUnicharUtils.h"
 
42
#include "nsXMLProcessingInstruction.h"
 
43
#include "nsParserUtils.h"
 
44
 
 
45
nsresult
 
46
NS_NewXMLProcessingInstruction(nsIContent** aInstancePtrResult,
 
47
                               const nsAString& aTarget,
 
48
                               const nsAString& aData)
 
49
{
 
50
  if (aTarget.Equals(NS_LITERAL_STRING("xml-stylesheet"))) {
 
51
    return NS_NewXMLStylesheetProcessingInstruction(aInstancePtrResult, aData);
 
52
  }
 
53
  *aInstancePtrResult = new nsXMLProcessingInstruction(aTarget, aData);
 
54
  NS_ENSURE_TRUE(*aInstancePtrResult, NS_ERROR_OUT_OF_MEMORY);
 
55
 
 
56
  NS_ADDREF(*aInstancePtrResult);
 
57
 
 
58
  return NS_OK;
 
59
}
 
60
 
 
61
nsXMLProcessingInstruction::nsXMLProcessingInstruction(const nsAString& aTarget,
 
62
                                                       const nsAString& aData) :
 
63
  mTarget(aTarget)
 
64
{
 
65
  nsGenericDOMDataNode::SetData(aData);
 
66
}
 
67
 
 
68
nsXMLProcessingInstruction::~nsXMLProcessingInstruction()
 
69
{
 
70
}
 
71
 
 
72
 
 
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)
 
79
 
 
80
 
 
81
NS_IMPL_ADDREF_INHERITED(nsXMLProcessingInstruction, nsGenericDOMDataNode)
 
82
NS_IMPL_RELEASE_INHERITED(nsXMLProcessingInstruction, nsGenericDOMDataNode)
 
83
 
 
84
 
 
85
NS_IMETHODIMP
 
86
nsXMLProcessingInstruction::GetTarget(nsAString& aTarget)
 
87
{
 
88
  aTarget.Assign(mTarget);
 
89
 
 
90
  return NS_OK;
 
91
}
 
92
 
 
93
NS_IMETHODIMP
 
94
nsXMLProcessingInstruction::SetData(const nsAString& aData)
 
95
{
 
96
  return SetNodeValue(aData);
 
97
}
 
98
 
 
99
NS_IMETHODIMP
 
100
nsXMLProcessingInstruction::GetData(nsAString& aData)
 
101
{
 
102
  return nsGenericDOMDataNode::GetData(aData);
 
103
}
 
104
 
 
105
PRBool
 
106
nsXMLProcessingInstruction::GetAttrValue(const nsAString& aAttr,
 
107
                                         nsAString& aValue)
 
108
{
 
109
  nsAutoString data;
 
110
 
 
111
  GetData(data);
 
112
  return nsParserUtils::GetQuotedAttributeValue(data, aAttr, aValue);
 
113
}
 
114
 
 
115
nsIAtom *
 
116
nsXMLProcessingInstruction::Tag() const
 
117
{
 
118
  return nsLayoutAtoms::processingInstructionTagName;
 
119
}
 
120
 
 
121
PRBool
 
122
nsXMLProcessingInstruction::IsContentOfType(PRUint32 aFlags) const
 
123
{
 
124
  return !(aFlags & ~ePROCESSING_INSTRUCTION);
 
125
}
 
126
 
 
127
NS_IMETHODIMP
 
128
nsXMLProcessingInstruction::GetNodeName(nsAString& aNodeName)
 
129
{
 
130
  aNodeName.Assign(mTarget);
 
131
  return NS_OK;
 
132
}
 
133
 
 
134
NS_IMETHODIMP
 
135
nsXMLProcessingInstruction::GetNodeValue(nsAString& aNodeValue)
 
136
{
 
137
  return nsGenericDOMDataNode::GetNodeValue(aNodeValue);
 
138
}
 
139
 
 
140
NS_IMETHODIMP
 
141
nsXMLProcessingInstruction::SetNodeValue(const nsAString& aNodeValue)
 
142
{
 
143
  return nsGenericDOMDataNode::SetNodeValue(aNodeValue);
 
144
}
 
145
 
 
146
NS_IMETHODIMP
 
147
nsXMLProcessingInstruction::GetNodeType(PRUint16* aNodeType)
 
148
{
 
149
  *aNodeType = (PRUint16)nsIDOMNode::PROCESSING_INSTRUCTION_NODE;
 
150
  return NS_OK;
 
151
}
 
152
 
 
153
NS_IMETHODIMP
 
154
nsXMLProcessingInstruction::CloneNode(PRBool aDeep, nsIDOMNode** aReturn)
 
155
{
 
156
  nsAutoString data;
 
157
  GetData(data);
 
158
 
 
159
  *aReturn = new nsXMLProcessingInstruction(mTarget, data);
 
160
  if (!*aReturn) {
 
161
    return NS_ERROR_OUT_OF_MEMORY;
 
162
  }
 
163
 
 
164
  NS_ADDREF(*aReturn);
 
165
 
 
166
  return NS_OK;
 
167
}
 
168
 
 
169
#ifdef DEBUG
 
170
void
 
171
nsXMLProcessingInstruction::List(FILE* out, PRInt32 aIndent) const
 
172
{
 
173
  NS_PRECONDITION(mDocument, "bad content");
 
174
 
 
175
  PRInt32 index;
 
176
  for (index = aIndent; --index >= 0; ) fputs("  ", out);
 
177
 
 
178
  fprintf(out, "Processing instruction refcount=%d<", mRefCnt.get());
 
179
 
 
180
  nsAutoString tmp;
 
181
  ToCString(tmp, 0, mText.GetLength());
 
182
  tmp.Insert(mTarget.get(), 0);
 
183
  fputs(NS_LossyConvertUCS2toASCII(tmp).get(), out);
 
184
 
 
185
  fputs(">\n", out);
 
186
}
 
187
 
 
188
void
 
189
nsXMLProcessingInstruction::DumpContent(FILE* out, PRInt32 aIndent,
 
190
                                        PRBool aDumpAll) const
 
191
{
 
192
}
 
193
#endif