Back to index

lightning-sunbird  0.9+nobinonly
txXPathNode.h
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 TransforMiiX XSLT processor 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) 2003
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *   Peter Van der Beken <peterv@propagandism.org>
00024  *
00025  * Alternatively, the contents of this file may be used under the terms of
00026  * either the GNU General Public License Version 2 or later (the "GPL"), or
00027  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00028  * in which case the provisions of the GPL or the LGPL are applicable instead
00029  * of those above. If you wish to allow use of your version of this file only
00030  * under the terms of either the GPL or the LGPL, and not to allow others to
00031  * use your version of this file under the terms of the MPL, indicate your
00032  * decision by deleting the provisions above and replace them with the notice
00033  * and other provisions required by the GPL or the LGPL. If you do not delete
00034  * the provisions above, a recipient may use your version of this file under
00035  * the terms of any one of the MPL, the GPL or the LGPL.
00036  *
00037  * ***** END LICENSE BLOCK ***** */
00038 
00039 #ifndef txXPathNode_h__
00040 #define txXPathNode_h__
00041 
00042 #ifdef TX_EXE
00043 #include "dom.h"
00044 #else
00045 #include "nsAutoPtr.h"
00046 #include "nsIContent.h"
00047 #include "nsIDocument.h"
00048 #include "nsIDOMNode.h"
00049 #include "nsINameSpaceManager.h"
00050 
00051 extern nsINameSpaceManager* gTxNameSpaceManager;
00052 #endif
00053 
00054 #ifdef TX_EXE
00055 typedef Node txXPathNodeType;
00056 #else
00057 typedef nsIDOMNode txXPathNodeType;
00058 #endif
00059 
00060 class txXPathNode
00061 {
00062 public:
00063     PRBool operator==(const txXPathNode& aNode) const;
00064     PRBool operator!=(const txXPathNode& aNode) const
00065     {
00066         return !(*this == aNode);
00067     }
00068 
00069 private:
00070     friend class txNodeSet;
00071     friend class txXPathNativeNode;
00072     friend class txXPathNodeUtils;
00073     friend class txXPathTreeWalker;
00074 
00075 #ifdef TX_EXE
00076     txXPathNode(NodeDefinition* aNode) : mInner(aNode)
00077     {
00078     }
00079     txXPathNode(const txXPathNode& aNode);
00080 
00081     NodeDefinition* mInner;
00082 #else
00083     txXPathNode(nsIDocument* aDocument) : mDocument(aDocument),
00084                                           mIndex(eDocument)
00085     {
00086     }
00087     txXPathNode(nsIContent* aContent, PRUint32 aIndex = eContent)
00088         : mContent(aContent),
00089           mIndex(aIndex)
00090     {
00091     }
00092     txXPathNode(const txXPathNode& aNode);
00093 
00094     PRBool isDocument() const
00095     {
00096         return mIndex == eDocument;
00097     };
00098     PRBool isContent() const
00099     {
00100         return mIndex == eContent;
00101     };
00102     PRBool isAttribute() const
00103     {
00104         return mIndex != eDocument && mIndex != eContent;
00105     };
00106 
00107     enum PositionType
00108     {
00109         eDocument = (PRUint32)-2,
00110         eContent = (PRUint32)-1
00111     };
00112     union {
00113         nsIDocument* mDocument;        // eDocument
00114         nsIContent* mContent;          // eContent, eAttribute
00115     };
00116     PRUint32 mIndex;
00117 #endif
00118 };
00119 
00120 class txNamespaceManager
00121 {
00122 public:
00123     static PRInt32 getNamespaceID(const nsAString& aNamespaceURI);
00124     static nsresult getNamespaceURI(const PRInt32 aID, nsAString& aResult);
00125 };
00126 
00127 /* static */
00128 inline PRInt32
00129 txNamespaceManager::getNamespaceID(const nsAString& aNamespaceURI)
00130 {
00131 #ifdef TX_EXE
00132     return txStandaloneNamespaceManager::getNamespaceID(aNamespaceURI);
00133 #else
00134     NS_ASSERTION(gTxNameSpaceManager, "No namespace manager");
00135 
00136     PRInt32 namespaceID = kNameSpaceID_Unknown;
00137     gTxNameSpaceManager->RegisterNameSpace(aNamespaceURI, namespaceID);
00138     return namespaceID;
00139 #endif
00140 }
00141 
00142 /* static */
00143 inline nsresult
00144 txNamespaceManager::getNamespaceURI(const PRInt32 aID, nsAString& aResult)
00145 {
00146 #ifdef TX_EXE
00147     return txStandaloneNamespaceManager::getNamespaceURI(aID, aResult);
00148 #else
00149     NS_ASSERTION(gTxNameSpaceManager, "No namespace manager");
00150 
00151     return gTxNameSpaceManager->GetNameSpaceURI(aID, aResult);
00152 #endif
00153 }
00154 
00155 #endif /* txXPathNode_h__ */