Back to index

lightning-sunbird  0.9+nobinonly
nsXMLProcessingInstruction.cpp
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
00002 /* ***** BEGIN LICENSE BLOCK *****
00003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is Mozilla Communicator client code.
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Netscape Communications Corporation.
00019  * Portions created by the Initial Developer are Copyright (C) 1998
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *
00024  * Alternatively, the contents of this file may be used under the terms of
00025  * either of the GNU General Public License Version 2 or later (the "GPL"),
00026  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00027  * in which case the provisions of the GPL or the LGPL are applicable instead
00028  * of those above. If you wish to allow use of your version of this file only
00029  * under the terms of either the GPL or the LGPL, and not to allow others to
00030  * use your version of this file under the terms of the MPL, indicate your
00031  * decision by deleting the provisions above and replace them with the notice
00032  * and other provisions required by the GPL or the LGPL. If you do not delete
00033  * the provisions above, a recipient may use your version of this file under
00034  * the terms of any one of the MPL, the GPL or the LGPL.
00035  *
00036  * ***** END LICENSE BLOCK ***** */
00037 
00038 #include "nsGenericElement.h"
00039 #include "nsLayoutAtoms.h"
00040 #include "nsUnicharUtils.h"
00041 #include "nsXMLProcessingInstruction.h"
00042 #include "nsParserUtils.h"
00043 #include "nsContentCreatorFunctions.h"
00044 
00045 nsresult
00046 NS_NewXMLProcessingInstruction(nsIContent** aInstancePtrResult,
00047                                nsNodeInfoManager *aNodeInfoManager,
00048                                const nsAString& aTarget,
00049                                const nsAString& aData)
00050 {
00051   NS_PRECONDITION(aNodeInfoManager, "Missing nodeinfo manager");
00052 
00053   if (aTarget.EqualsLiteral("xml-stylesheet")) {
00054     return NS_NewXMLStylesheetProcessingInstruction(aInstancePtrResult,
00055                                                     aNodeInfoManager, aData);
00056   }
00057 
00058   *aInstancePtrResult = nsnull;
00059 
00060   nsXMLProcessingInstruction *instance =
00061     new nsXMLProcessingInstruction(aNodeInfoManager, aTarget, aData);
00062   if (!instance) {
00063     return NS_ERROR_OUT_OF_MEMORY;
00064   }
00065 
00066   NS_ADDREF(*aInstancePtrResult = instance);
00067 
00068   return NS_OK;
00069 }
00070 
00071 nsXMLProcessingInstruction::nsXMLProcessingInstruction(nsNodeInfoManager *aNodeInfoManager,
00072                                                        const nsAString& aTarget,
00073                                                        const nsAString& aData)
00074   : nsGenericDOMDataNode(aNodeInfoManager),
00075     mTarget(aTarget)
00076 {
00077   nsGenericDOMDataNode::SetData(aData);
00078 }
00079 
00080 nsXMLProcessingInstruction::~nsXMLProcessingInstruction()
00081 {
00082 }
00083 
00084 
00085 // QueryInterface implementation for nsXMLProcessingInstruction
00086 NS_INTERFACE_MAP_BEGIN(nsXMLProcessingInstruction)
00087   NS_INTERFACE_MAP_ENTRY(nsIDOMNode)
00088   NS_INTERFACE_MAP_ENTRY(nsIDOMProcessingInstruction)
00089   NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(ProcessingInstruction)
00090 NS_INTERFACE_MAP_END_INHERITING(nsGenericDOMDataNode)
00091 
00092 
00093 NS_IMPL_ADDREF_INHERITED(nsXMLProcessingInstruction, nsGenericDOMDataNode)
00094 NS_IMPL_RELEASE_INHERITED(nsXMLProcessingInstruction, nsGenericDOMDataNode)
00095 
00096 
00097 NS_IMETHODIMP
00098 nsXMLProcessingInstruction::GetTarget(nsAString& aTarget)
00099 {
00100   aTarget.Assign(mTarget);
00101 
00102   return NS_OK;
00103 }
00104 
00105 NS_IMETHODIMP
00106 nsXMLProcessingInstruction::SetData(const nsAString& aData)
00107 {
00108   return SetNodeValue(aData);
00109 }
00110 
00111 NS_IMETHODIMP
00112 nsXMLProcessingInstruction::GetData(nsAString& aData)
00113 {
00114   return nsGenericDOMDataNode::GetData(aData);
00115 }
00116 
00117 PRBool
00118 nsXMLProcessingInstruction::GetAttrValue(nsIAtom *aName, nsAString& aValue)
00119 {
00120   nsAutoString data;
00121 
00122   GetData(data);
00123   return nsParserUtils::GetQuotedAttributeValue(data, aName, aValue);
00124 }
00125 
00126 nsIAtom *
00127 nsXMLProcessingInstruction::Tag() const
00128 {
00129   return nsLayoutAtoms::processingInstructionTagName;
00130 }
00131 
00132 PRBool
00133 nsXMLProcessingInstruction::IsContentOfType(PRUint32 aFlags) const
00134 {
00135   return !(aFlags & ~ePROCESSING_INSTRUCTION);
00136 }
00137 
00138 // virtual
00139 PRBool
00140 nsXMLProcessingInstruction::MayHaveFrame() const
00141 {
00142   return PR_FALSE;
00143 }
00144 
00145 NS_IMETHODIMP
00146 nsXMLProcessingInstruction::GetNodeName(nsAString& aNodeName)
00147 {
00148   aNodeName.Assign(mTarget);
00149   return NS_OK;
00150 }
00151 
00152 NS_IMETHODIMP
00153 nsXMLProcessingInstruction::GetNodeValue(nsAString& aNodeValue)
00154 {
00155   return nsGenericDOMDataNode::GetNodeValue(aNodeValue);
00156 }
00157 
00158 NS_IMETHODIMP
00159 nsXMLProcessingInstruction::SetNodeValue(const nsAString& aNodeValue)
00160 {
00161   return nsGenericDOMDataNode::SetNodeValue(aNodeValue);
00162 }
00163 
00164 NS_IMETHODIMP
00165 nsXMLProcessingInstruction::GetNodeType(PRUint16* aNodeType)
00166 {
00167   *aNodeType = (PRUint16)nsIDOMNode::PROCESSING_INSTRUCTION_NODE;
00168   return NS_OK;
00169 }
00170 
00171 NS_IMETHODIMP
00172 nsXMLProcessingInstruction::CloneNode(PRBool aDeep, nsIDOMNode** aReturn)
00173 {
00174   nsAutoString data;
00175   GetData(data);
00176 
00177   nsXMLProcessingInstruction *pi =
00178     new nsXMLProcessingInstruction(GetNodeInfoManager(), mTarget, data);
00179   if (!pi) {
00180     return NS_ERROR_OUT_OF_MEMORY;
00181   }
00182 
00183   NS_ADDREF(*aReturn = pi);
00184 
00185   return NS_OK;
00186 }
00187 
00188 #ifdef DEBUG
00189 void
00190 nsXMLProcessingInstruction::List(FILE* out, PRInt32 aIndent) const
00191 {
00192   NS_PRECONDITION(IsInDoc(), "bad content");
00193 
00194   PRInt32 index;
00195   for (index = aIndent; --index >= 0; ) fputs("  ", out);
00196 
00197   fprintf(out, "Processing instruction refcount=%d<", mRefCnt.get());
00198 
00199   nsAutoString tmp;
00200   ToCString(tmp, 0, mText.GetLength());
00201   tmp.Insert(mTarget.get(), 0);
00202   fputs(NS_LossyConvertUCS2toASCII(tmp).get(), out);
00203 
00204   fputs(">\n", out);
00205 }
00206 
00207 void
00208 nsXMLProcessingInstruction::DumpContent(FILE* out, PRInt32 aIndent,
00209                                         PRBool aDumpAll) const
00210 {
00211 }
00212 #endif