Back to index

lightning-sunbird  0.9+nobinonly
txMozillaXMLOutput.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) 2001
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_MOZILLA_XML_OUTPUT_H
00040 #define TRANSFRMX_MOZILLA_XML_OUTPUT_H
00041 
00042 #include "txXMLEventHandler.h"
00043 #include "nsAutoPtr.h"
00044 #include "nsIScriptLoaderObserver.h"
00045 #include "txOutputFormat.h"
00046 #include "nsCOMArray.h"
00047 #include "nsICSSLoaderObserver.h"
00048 #include "txStack.h"
00049 
00050 class nsIContent;
00051 class nsIDOMDocument;
00052 class nsIAtom;
00053 class nsIDOMDocumentFragment;
00054 class nsIDOMElement;
00055 class nsIStyleSheet;
00056 class nsIDOMNode;
00057 class nsITransformObserver;
00058 
00059 class txTransformNotifier : public nsIScriptLoaderObserver,
00060                             public nsICSSLoaderObserver
00061 {
00062 public:
00063     txTransformNotifier();
00064     virtual ~txTransformNotifier();
00065 
00066     NS_DECL_ISUPPORTS
00067     NS_DECL_NSISCRIPTLOADEROBSERVER
00068     
00069     // nsICSSLoaderObserver
00070     NS_IMETHOD StyleSheetLoaded(nsICSSStyleSheet* aSheet, PRBool aNotify);
00071 
00072     void Init(nsITransformObserver* aObserver);
00073     void AddScriptElement(nsIScriptElement* aElement);
00074     void AddStyleSheet(nsIStyleSheet* aStyleSheet);
00075     void OnTransformEnd(nsresult aResult = NS_OK);
00076     void OnTransformStart();
00077     void SetOutputDocument(nsIDOMDocument* aDocument);
00078 
00079 private:
00080     void SignalTransformEnd(nsresult aResult = NS_OK);
00081 
00082     nsCOMPtr<nsIDOMDocument> mDocument;
00083     nsCOMPtr<nsITransformObserver> mObserver;
00084     nsCOMArray<nsIScriptElement> mScriptElements;
00085     nsCOMArray<nsIStyleSheet> mStylesheets;
00086     PRPackedBool mInTransform;
00087 };
00088 
00089 class txMozillaXMLOutput : public txAOutputXMLEventHandler
00090 {
00091 public:
00092     txMozillaXMLOutput(const nsAString& aRootName,
00093                        PRInt32 aRootNsID,
00094                        txOutputFormat* aFormat,
00095                        nsIDOMDocument* aSourceDocument,
00096                        nsIDOMDocument* aResultDocument,
00097                        nsITransformObserver* aObserver);
00098     txMozillaXMLOutput(txOutputFormat* aFormat,
00099                        nsIDOMDocumentFragment* aFragment);
00100     virtual ~txMozillaXMLOutput();
00101 
00102     TX_DECL_TXAXMLEVENTHANDLER
00103     TX_DECL_TXAOUTPUTXMLEVENTHANDLER
00104 
00105 private:
00106     void closePrevious(PRInt8 aAction);
00107     void startHTMLElement(nsIDOMElement* aElement, PRBool aXHTML);
00108     void endHTMLElement(nsIDOMElement* aElement);
00109     void processHTTPEquiv(nsIAtom* aHeader, const nsAString& aValue);
00110     nsresult createResultDocument(const nsAString& aName, PRInt32 aNsID,
00111                                   nsIDOMDocument* aSourceDocument,
00112                                   nsIDOMDocument* aResultDocument);
00113     nsresult createHTMLElement(const nsAString& aName,
00114                                nsIDOMElement** aResult);
00115 
00116     nsCOMPtr<nsIDOMDocument> mDocument;
00117     nsCOMPtr<nsIDOMNode> mCurrentNode;
00118     nsCOMPtr<nsIDOMNode> mParentNode;
00119     nsCOMPtr<nsIContent> mRootContent;
00120 
00121     nsCOMPtr<nsIDOMNode> mNonAddedParent;
00122     nsCOMPtr<nsIDOMNode> mNonAddedNode;
00123 
00124     nsRefPtr<txTransformNotifier> mNotifier;
00125 
00126     PRUint32 mTreeDepth, mBadChildLevel;
00127     nsCString mRefreshString;
00128 
00129     txStack mTableStateStack;
00130     enum TableState { 
00131         NORMAL,      // An element needing no special treatment
00132         TABLE,       // A HTML table element
00133         ADDED_TBODY  // An inserted tbody not coming from the stylesheet
00134     };
00135     TableState mTableState;
00136 
00137     nsAutoString mText;
00138 
00139     txOutputFormat mOutputFormat;
00140 
00141     PRPackedBool mDontAddCurrent;
00142 
00143     PRPackedBool mHaveTitleElement;
00144     PRPackedBool mHaveBaseElement;
00145 
00146     PRPackedBool mDocumentIsHTML;
00147     PRPackedBool mCreatingNewDocument;
00148 
00149     enum txAction { eCloseElement = 1, eFlushText = 2 };
00150 };
00151 
00152 #endif