Back to index

lightning-sunbird  0.9+nobinonly
txMozillaXSLTProcessor.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) 2002
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 TRANSFRMX_TXMOZILLAXSLTPROCESSOR_H
00040 #define TRANSFRMX_TXMOZILLAXSLTPROCESSOR_H
00041 
00042 #include "ExprResult.h"
00043 #include "nsIDocumentTransformer.h"
00044 #include "nsIVariant.h"
00045 #include "nsIXSLTProcessor.h"
00046 #include "nsVoidArray.h"
00047 #include "nsWeakPtr.h"
00048 #include "txExpandedNameMap.h"
00049 #include "txXMLEventHandler.h"
00050 #include "nsIXSLTProcessorObsolete.h"
00051 #include "nsIXSLTProcessorPrivate.h"
00052 #include "txXSLTProcessor.h"
00053 #include "nsVoidArray.h"
00054 #include "nsAutoPtr.h"
00055 #include "nsIDocumentObserver.h"
00056 #include "txNamespaceMap.h"
00057 
00058 class nsIURI;
00059 class nsIXMLContentSink;
00060 class nsIDOMNode;
00061 class nsIPrincipal;
00062 class txResultRecycler;
00063 
00064 /* bacd8ad0-552f-11d3-a9f7-000064657374 */
00065 #define TRANSFORMIIX_XSLT_PROCESSOR_CID   \
00066 { 0xbacd8ad0, 0x552f, 0x11d3, {0xa9, 0xf7, 0x00, 0x00, 0x64, 0x65, 0x73, 0x74} }
00067 
00068 #define TRANSFORMIIX_XSLT_PROCESSOR_CONTRACTID \
00069 "@mozilla.org/document-transformer;1?type=xslt"
00070 
00071 #define XSLT_MSGS_URL  "chrome://global/locale/xslt/xslt.properties"
00072 
00073 class txVariable : public txIGlobalParameter
00074 {
00075 public:
00076     txVariable(nsIVariant *aValue) : mValue(aValue)
00077     {
00078         NS_ASSERTION(aValue, "missing value");
00079     }
00080     txVariable(txAExprResult* aValue) : mTxValue(aValue)
00081     {
00082         NS_ASSERTION(aValue, "missing value");
00083     }
00084     nsresult getValue(txAExprResult** aValue)
00085     {
00086         NS_ASSERTION(mValue || mTxValue, "variablevalue is null");
00087 
00088         if (!mTxValue) {
00089             nsresult rv = Convert(mValue, getter_AddRefs(mTxValue));
00090             NS_ENSURE_SUCCESS(rv, rv);
00091         }
00092 
00093         *aValue = mTxValue;
00094         NS_ADDREF(*aValue);
00095 
00096         return NS_OK;
00097     }
00098     nsresult getValue(nsIVariant** aValue)
00099     {
00100         *aValue = mValue;
00101         NS_ADDREF(*aValue);
00102         return NS_OK;
00103     }
00104     void setValue(nsIVariant* aValue)
00105     {
00106         NS_ASSERTION(aValue, "setting variablevalue to null");
00107         mValue = aValue;
00108         mTxValue = nsnull;
00109     }
00110     void setValue(txAExprResult* aValue)
00111     {
00112         NS_ASSERTION(aValue, "setting variablevalue to null");
00113         mValue = nsnull;
00114         mTxValue = aValue;
00115     }
00116 
00117 private:
00118     static nsresult Convert(nsIVariant *aValue, txAExprResult** aResult);
00119 
00120     nsCOMPtr<nsIVariant> mValue;
00121     nsRefPtr<txAExprResult> mTxValue;
00122 };
00123 
00127 class txMozillaXSLTProcessor : public nsIXSLTProcessor,
00128                                public nsIXSLTProcessorObsolete,
00129                                public nsIXSLTProcessorPrivate,
00130                                public nsIDocumentTransformer,
00131                                public nsIDocumentTransformer_1_8_BRANCH,
00132                                public nsIDocumentObserver
00133 {
00134 public:
00138     txMozillaXSLTProcessor();
00139 
00143     virtual ~txMozillaXSLTProcessor();
00144 
00145     // nsISupports interface
00146     NS_DECL_ISUPPORTS
00147 
00148     // nsIXSLTProcessor interface
00149     NS_DECL_NSIXSLTPROCESSOR
00150 
00151     // nsIXSLTProcessorObsolete interface
00152     NS_DECL_NSIXSLTPROCESSOROBSOLETE
00153 
00154     // nsIXSLTProcessorPrivate interface
00155     NS_DECL_NSIXSLTPROCESSORPRIVATE
00156 
00157     // nsIDocumentTransformer interface
00158     NS_IMETHOD SetTransformObserver(nsITransformObserver* aObserver);
00159     NS_IMETHOD LoadStyleSheet(nsIURI* aUri, nsILoadGroup* aLoadGroup,
00160                               nsIPrincipal* aCallerPrincipal);
00161     NS_IMETHOD SetSourceContentModel(nsIDOMNode* aSource);
00162     NS_IMETHOD CancelLoads() {return NS_OK;};
00163     NS_IMETHOD AddXSLTParamNamespace(const nsString& aPrefix,
00164                                      const nsString& aNamespace);
00165     NS_IMETHOD AddXSLTParam(const nsString& aName,
00166                             const nsString& aNamespace,
00167                             const nsString& aSelect,
00168                             const nsString& aValue,
00169                             nsIDOMNode* aContext);
00170 
00171     // nsIDocumentObserver interface
00172     NS_DECL_NSIDOCUMENTOBSERVER
00173 
00174     nsresult setStylesheet(txStylesheet* aStylesheet);
00175     void reportError(nsresult aResult, const PRUnichar *aErrorText,
00176                      const PRUnichar *aSourceText);
00177 
00178     nsIDOMNode *GetSourceContentModel()
00179     {
00180         return mSource;
00181     }
00182 
00183     nsresult TransformToDoc(nsIDOMDocument *aOutputDoc,
00184                             nsIDOMDocument **aResult);
00185 
00186     PRBool IsLoadDisabled()
00187     {
00188         return (mFlags & DISABLE_ALL_LOADS) != 0;
00189     }
00190 
00191 private:
00192     nsresult DoTransform();
00193     void notifyError();
00194     nsresult ensureStylesheet();
00195 
00196     nsRefPtr<txStylesheet> mStylesheet;
00197     nsIDocument* mStylesheetDocument; // weak
00198     nsCOMPtr<nsIContent> mEmbeddedStylesheetRoot;
00199 
00200     nsCOMPtr<nsIDOMNode> mSource;
00201     nsresult mTransformResult;
00202     nsresult mCompileResult;
00203     nsString mErrorText, mSourceText;
00204     nsCOMPtr<nsITransformObserver> mObserver;
00205     txExpandedNameMap mVariables;
00206     txNamespaceMap mParamNamespaceMap;
00207     nsRefPtr<txResultRecycler> mRecycler;
00208 
00209     PRUint32 mFlags;
00210 };
00211 
00212 extern nsresult TX_LoadSheet(nsIURI* aUri, txMozillaXSLTProcessor* aProcessor,
00213                              nsILoadGroup* aLoadGroup,
00214                              nsIPrincipal* aCallerPrincipal);
00215 
00216 extern nsresult TX_CompileStylesheet(nsIDOMNode* aNode,
00217                                      txMozillaXSLTProcessor* aProcessor,
00218                                      txStylesheet** aStylesheet);
00219 
00220 #endif