Back to index

lightning-sunbird  0.9+nobinonly
mozXMLTermSession.h
Go to the documentation of this file.
00001 /* ***** BEGIN LICENSE BLOCK *****
00002  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00003  *
00004  * The contents of this file are subject to the Mozilla Public License Version
00005  * 1.1 (the "License"); you may not use this file except in compliance with
00006  * the License. You may obtain a copy of the License at
00007  * http://www.mozilla.org/MPL/
00008  *
00009  * Software distributed under the License is distributed on an "AS IS" basis,
00010  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00011  * for the specific language governing rights and limitations under the
00012  * License.
00013  *
00014  * The Original Code is XMLterm.
00015  *
00016  * The Initial Developer of the Original Code is
00017  * Ramalingam Saravanan.
00018  * Portions created by the Initial Developer are Copyright (C) 1999
00019  * the Initial Developer. All Rights Reserved.
00020  *
00021  * Contributor(s):
00022  *
00023  * Alternatively, the contents of this file may be used under the terms of
00024  * either the GNU General Public License Version 2 or later (the "GPL"), or
00025  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00026  * in which case the provisions of the GPL or the LGPL are applicable instead
00027  * of those above. If you wish to allow use of your version of this file only
00028  * under the terms of either the GPL or the LGPL, and not to allow others to
00029  * use your version of this file under the terms of the MPL, indicate your
00030  * decision by deleting the provisions above and replace them with the notice
00031  * and other provisions required by the GPL or the LGPL. If you do not delete
00032  * the provisions above, a recipient may use your version of this file under
00033  * the terms of any one of the MPL, the GPL or the LGPL.
00034  *
00035  * ***** END LICENSE BLOCK ***** */
00036 
00037 // mozXMLTermSession.h: class to manage session input/output display
00038 // NOTE: This class is getting too unwieldy. It should be modularized,
00039 //       using a separate class for entries, for example, once the dust
00040 //       settles.
00041 
00042 #include "nscore.h"
00043 #include "prlog.h"
00044 
00045 #include "nsCOMPtr.h"
00046 #include "nsString.h"
00047 
00048 #include "nsIGenericFactory.h"
00049 #include "nsIPresShell.h"
00050 #include "nsIDOMNode.h"
00051 #include "nsIDOMDocument.h"
00052 
00053 #include "nsIContent.h"
00054 
00055 #include "mozXMLT.h"
00056 #include "mozILineTerm.h"
00057 #include "mozIXMLTerminal.h"
00058 #include "mozIXMLTermStream.h"
00059 
00060 
00061 class mozXMLTermSession
00062 {
00063   public:
00064 
00065   mozXMLTermSession();
00066   virtual ~mozXMLTermSession();
00067 
00075   NS_IMETHOD Init(mozIXMLTerminal* aXMLTerminal,
00076                   nsIPresShell* aPresShell,
00077                   nsIDOMDocument* aDOMDocument,
00078                   PRInt32 nRows, PRInt32 nCols);
00079 
00082   NS_IMETHOD Finalize(void);
00083 
00087   NS_IMETHOD Resize(mozILineTermAux* lineTermAux);
00088 
00094   NS_IMETHOD Preprocess(const nsString& aString,
00095                         PRBool& consumed,
00096                         PRBool& checkSize);
00097 
00103   NS_IMETHOD ReadAll(mozILineTermAux* lineTermAux, PRBool& processedData);
00104 
00110   NS_IMETHOD ExportHTML(const PRUnichar* aFilename,
00111                         PRInt32 permissions,
00112                         const PRUnichar* style,
00113                         PRUint32 refreshSeconds,
00114                         PRBool forceExport,
00115                         PRBool* exported);
00116 
00121   NS_IMETHOD Abort(mozILineTermAux* lineTermAux,
00122                    nsString& abortCode);
00123 
00127   NS_IMETHOD GetCurrentEntryNumber(PRInt32 *aNumber);
00128 
00132   NS_IMETHOD GetHistory(PRInt32 *aHistory);
00133 
00137   NS_IMETHOD SetHistory(PRInt32 aHistory);
00138 
00142   NS_IMETHOD GetPrompt(PRUnichar **aPrompt);
00143 
00147   NS_IMETHOD SetPrompt(const PRUnichar* aPrompt);
00148 
00152   NS_IMETHOD GetScreenMode(PRBool* aFlag);
00153 
00154 protected:
00155 
00159   enum SessionElementType {
00160     SESSION_ELEMENT = 0,
00161     ENTRY_ELEMENT,
00162     INPUT_ELEMENT,
00163     OUTPUT_ELEMENT,
00164     PROMPT_ELEMENT,
00165     COMMAND_ELEMENT,
00166     STDIN_ELEMENT,
00167     STDOUT_ELEMENT,
00168     STDERR_ELEMENT,
00169     MIXED_ELEMENT,
00170     WARNING_ELEMENT,
00171     SESSION_ELEMENT_TYPES
00172   };
00173 
00175   enum SessionEventType {
00176     CLICK_EVENT = 0,
00177     SESSION_EVENT_TYPES
00178   };
00179 
00181   enum OutputType {
00182     LINE_OUTPUT = 0,
00183     SCREEN_OUTPUT,
00184     STREAM_OUTPUT,
00185     OUTPUT_TYPES
00186   };
00187 
00189   enum OutputDisplayType {
00190     NO_NODE          = 0,
00191     PRE_STDOUT_NODE,
00192     PRE_STDERR_NODE,
00193     PRE_STDIN_NODE,
00194     DIV_MIXED_NODE,
00195     SPAN_DUMMY_NODE,
00196     OUTPUT_DISPLAY_TYPES
00197   };
00198 
00200   enum OutputMarkupType {
00201     PLAIN_TEXT = 0,
00202     TEXT_FRAGMENT,
00203     JS_FRAGMENT,
00204     HTML_FRAGMENT,
00205     HTML_DOCUMENT,
00206     XML_DOCUMENT,
00207     INSECURE_FRAGMENT,
00208     OVERFLOW_FRAGMENT,
00209     INCOMPLETE_FRAGMENT,
00210     OUTPUT_MARKUP_TYPES
00211   };
00212 
00214   enum AutoDetectOption {
00215     NO_MARKUP = 0,
00216     FIRST_LINE,
00217     ANY_LINE
00218   };
00219 
00221   enum FlushActionType {
00222     DISPLAY_INCOMPLETE_FLUSH = 0,
00223     SPLIT_INCOMPLETE_FLUSH,
00224     CLEAR_INCOMPLETE_FLUSH,
00225     CLOSE_INCOMPLETE_FLUSH
00226   };
00227 
00229   enum MetaCommandType {
00230     NO_META_COMMAND    = 0,
00231     DEFAULT_META_COMMAND,
00232     HTTP_META_COMMAND,
00233     JS_META_COMMAND,
00234     TREE_META_COMMAND,
00235     LS_META_COMMAND,
00236     META_COMMAND_TYPES
00237   };
00238 
00240   enum FileType {
00241     PLAIN_FILE      = 0,
00242     DIRECTORY_FILE,
00243     EXECUTABLE_FILE,
00244     FILE_TYPES
00245   };
00246 
00248   enum TreeActionCode {
00249     TREE_MOVE_UP      = 1,
00250     TREE_MOVE_DOWN    = 2,
00251     TREE_MOVE_LEFT    = 3,
00252     TREE_MOVE_RIGHT   = 4,
00253     TREE_PRINT_ATTS   = 5,
00254     TREE_PRINT_HTML   = 6,
00255     TREE_ACTION_CODES = 7
00256   };
00257 
00263   NS_IMETHOD DisplayInput(const nsString& aString,
00264                           const nsString& aStyle,
00265                           PRInt32 cursorCol);
00266 
00273   NS_IMETHOD AutoDetectMarkup(const nsString& aString,
00274                               PRBool firstOutputLine,
00275                               PRBool secure);
00276 
00282   NS_IMETHOD InitStream(const nsString& streamURL,
00283                         OutputMarkupType streamMarkupType,
00284                         PRBool streamIsSecure);
00285 
00287   NS_IMETHOD BreakOutput(PRBool positionCursorBelow);
00288 
00296   NS_IMETHOD ProcessOutput(const nsString& aString,
00297                            const nsString& aStyle,
00298                            PRBool newline,
00299                            PRBool streamOutput);
00300 
00306   NS_IMETHOD LimitOutputLines(PRBool deleteAllOld);
00307 
00315   NS_IMETHOD AppendOutput(const nsString& aString,
00316                           const nsString& aStyle,
00317                           PRBool newline);
00318 
00324   NS_IMETHOD AppendLineLS(const nsString& aString,
00325                           const nsString& aStyle);
00326 
00340   NS_IMETHOD InsertFragment(const nsString& aString,
00341                             nsIDOMNode* parentNode,
00342                             PRInt32 entryNumber = -1,
00343                             nsIDOMNode* beforeNode = nsnull,
00344                             PRBool replace = PR_FALSE);
00345 
00351   void SubstituteCommandNumber(nsString& aString,
00352                                PRInt32 aNumber);
00353 
00358   void SanitizeAttribute(nsString& aAttrValue,
00359                          const char* aEventName);
00360 
00376   NS_IMETHOD DeepSanitizeFragment(nsCOMPtr<nsIDOMNode>& domNode,
00377                                   nsIDOMNode* parentNode,
00378                                   PRInt32 entryNumber);
00379 
00384   NS_IMETHOD DeepRefreshEventHandlers(nsCOMPtr<nsIDOMNode>& domNode);
00385 
00390   NS_IMETHOD FlushOutput(FlushActionType flushAction);
00391 
00393   void PositionOutputCursor(mozILineTermAux* lineTermAux);
00394 
00396   NS_IMETHOD ScrollToBottomLeft(void);
00397 
00402   NS_IMETHOD NewPreface(void);
00403 
00414   NS_IMETHOD NewEntry(const nsString& aPrompt);
00415 
00420   NS_IMETHOD NewScreen(void);
00421 
00424   NS_IMETHOD GetRow(PRInt32 aRow, nsIDOMNode** aRowNode);
00425 
00428   NS_IMETHOD PositionScreenCursor(PRInt32 aRow, PRInt32 aCol);
00429 
00435   NS_IMETHOD NewRow(nsIDOMNode* beforeRowNode,
00436                     nsIDOMNode** resultNode);
00437 
00444   NS_IMETHOD DisplayRow(const nsString& aString, const nsString& aStyle,
00445                         PRInt32 aRow);
00446 
00450   NS_IMETHOD NewBreak(nsIDOMNode* parentNode);
00451 
00468   NS_IMETHOD NewElementWithText(const nsString& tagName,
00469                                 const nsString& name, PRInt32 number,
00470                                 nsIDOMNode* parentNode,
00471                                 nsCOMPtr<nsIDOMNode>& blockNode,
00472                                 nsCOMPtr<nsIDOMNode>& textNode,
00473                                 nsIDOMNode* beforeNode = nsnull);
00474 
00485   NS_IMETHOD NewAnchor(const nsString& classAttribute,
00486                        PRInt32 number,
00487                        nsIDOMNode* parentNode,
00488                        nsCOMPtr<nsIDOMNode>& anchorNode);
00489 
00504   NS_IMETHOD NewElement(const nsString& tagName,
00505                         const nsString& name, PRInt32 number,
00506                         nsIDOMNode* parentNode,
00507                         nsCOMPtr<nsIDOMNode>& blockNode,
00508                         nsIDOMNode* beforeNode = nsnull);
00509 
00515   NS_IMETHOD NewTextNode( nsIDOMNode* parentNode,
00516                           nsCOMPtr<nsIDOMNode>& textNode);
00517 
00529   NS_IMETHOD NewIFrame(nsIDOMNode* parentNode,
00530                        PRInt32 number,
00531                        PRInt32 frameBorder,
00532                        const nsString& src,
00533                        const nsString& width,
00534                        const nsString& height);
00535 
00541   NS_IMETHOD SetEventAttributes(const nsString& name,
00542                                 PRInt32 number,
00543                                 nsCOMPtr<nsIDOMNode>& domNode);
00544 
00549   NS_IMETHOD SetDOMText(nsCOMPtr<nsIDOMNode>& textNode,
00550                         const nsString& aString);
00551 
00556   PRBool IsTextNode(nsIDOMNode *aNode);
00557 
00563   PRBool IsPREInlineNode(nsIDOMNode* aNode);
00564 
00575   NS_IMETHOD ToHTMLString(nsIDOMNode* aNode,
00576                           nsString& indentString,
00577                           nsString& htmlString,
00578                           PRBool deepContent = PR_FALSE,
00579                           PRBool insidePRENode = PR_FALSE);
00580 
00587   void TraverseDOMTree(FILE* fileStream,
00588                        nsIDOMNode* rootNode,
00589                        nsCOMPtr<nsIDOMNode>& currentNode,
00590                        TreeActionCode treeActionCode);
00591 
00593   static const char* const sessionElementNames[SESSION_ELEMENT_TYPES];
00594 
00596   static const char* const sessionEventNames[SESSION_EVENT_TYPES];
00597 
00599   static const char* const metaCommandNames[META_COMMAND_TYPES];
00600 
00602   static const char* const fileTypeNames[FILE_TYPES];
00603 
00605   static const char* const treeActionNames[TREE_ACTION_CODES];
00606 
00608   PRBool mInitialized;
00609 
00610 
00612   mozIXMLTerminal*   mXMLTerminal;               // non-owning reference
00613 
00615   nsIPresShell*      mPresShell;                 // non-owning reference (??)
00616 
00618   nsIDOMDocument*    mDOMDocument;               // non-owning reference (??)
00619 
00620 
00622   nsCOMPtr<nsIDOMNode> mBodyNode;
00623 
00625   nsCOMPtr<nsIDOMNode> mMenusNode;
00626 
00628   nsCOMPtr<nsIDOMNode> mSessionNode;
00629 
00631   nsCOMPtr<nsIDOMNode> mCurrentDebugNode;
00632 
00633 
00635   nsCOMPtr<nsIDOMNode> mStartEntryNode;
00636 
00638   nsCOMPtr<nsIDOMNode> mCurrentEntryNode;
00639 
00641   PRInt32              mMaxHistory;
00642 
00644   PRInt32              mStartEntryNumber;
00645 
00647   PRInt32              mCurrentEntryNumber;
00648 
00650   PRBool               mEntryHasOutput;
00651 
00653   nsCOMPtr<nsIDOMNode> mPromptTextNode;
00654 
00656   nsCOMPtr<nsIDOMNode> mCommandSpanNode;
00657 
00659   nsCOMPtr<nsIDOMNode> mInputTextNode;
00660 
00661 
00663   nsCOMPtr<nsIDOMNode> mOutputBlockNode;
00664 
00666   nsCOMPtr<nsIDOMNode> mOutputDisplayNode;
00667 
00669   nsCOMPtr<nsIDOMNode> mOutputTextNode;
00670 
00672   PRInt32 mOutputTextOffset;
00673 
00675   nsCOMPtr<mozIXMLTermStream> mXMLTermStream;
00676 
00677 
00679   OutputType    mOutputType;
00680 
00682   OutputDisplayType    mOutputDisplayType;
00683 
00685   OutputMarkupType     mOutputMarkupType;
00686 
00687 
00689   MetaCommandType      mMetaCommandType;
00690 
00692   AutoDetectOption     mAutoDetect;
00693 
00694 
00696   PRBool               mFirstOutputLine;
00697 
00698 
00700   PRInt32              mEntryOutputLines;
00701 
00703   PRInt32              mPreTextBufferLines;
00704 
00706   nsString             mPreTextIncomplete;
00707 
00709   nsString             mPreTextBuffered;
00710 
00712   nsString             mPreTextDisplayed;
00713 
00714 
00716   nsCOMPtr<nsIDOMNode> mScreenNode;
00717 
00719   PRInt32 mScreenRows;
00720 
00722   PRInt32 mScreenCols;
00723 
00725   PRInt32 mTopScrollRow;
00726 
00728   PRInt32 mBotScrollRow;
00729 
00730 
00732   PRBool               mRestoreInputEcho;
00733 
00734 
00736   PRInt32  mCountExportHTML;
00737 
00739   nsString mLastExportHTML;
00740 
00741 
00743   nsString             mShellPrompt;
00744 
00746   nsString             mPromptHTML;
00747 
00749   nsString             mFragmentBuffer;
00750 
00751 };