/parser/htmlparser/src/nsViewSourceHTML.h

http://github.com/zpao/v8monkey · C Header · 166 lines · 91 code · 25 blank · 50 comment · 0 complexity · f773abb710410c31d6d793d4a213f26c MD5 · raw file

  1. /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
  2. /* ***** BEGIN LICENSE BLOCK *****
  3. * Version: MPL 1.1/GPL 2.0/LGPL 2.1
  4. *
  5. * The contents of this file are subject to the Mozilla Public License Version
  6. * 1.1 (the "License"); you may not use this file except in compliance with
  7. * the License. You may obtain a copy of the License at
  8. * http://www.mozilla.org/MPL/
  9. *
  10. * Software distributed under the License is distributed on an "AS IS" basis,
  11. * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  12. * for the specific language governing rights and limitations under the
  13. * License.
  14. *
  15. * The Original Code is mozilla.org code.
  16. *
  17. * The Initial Developer of the Original Code is
  18. * Netscape Communications Corporation.
  19. * Portions created by the Initial Developer are Copyright (C) 1998
  20. * the Initial Developer. All Rights Reserved.
  21. *
  22. * Contributor(s):
  23. *
  24. * Alternatively, the contents of this file may be used under the terms of
  25. * either of the GNU General Public License Version 2 or later (the "GPL"),
  26. * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  27. * in which case the provisions of the GPL or the LGPL are applicable instead
  28. * of those above. If you wish to allow use of your version of this file only
  29. * under the terms of either the GPL or the LGPL, and not to allow others to
  30. * use your version of this file under the terms of the MPL, indicate your
  31. * decision by deleting the provisions above and replace them with the notice
  32. * and other provisions required by the GPL or the LGPL. If you do not delete
  33. * the provisions above, a recipient may use your version of this file under
  34. * the terms of any one of the MPL, the GPL or the LGPL.
  35. *
  36. * ***** END LICENSE BLOCK ***** */
  37. /**
  38. * MODULE NOTES:
  39. * @update gess 4/8/98
  40. *
  41. *
  42. */
  43. #ifndef __NS_VIEWSOURCE_HTML_
  44. #define __NS_VIEWSOURCE_HTML_
  45. #include "nsIDTD.h"
  46. #include "nsISupports.h"
  47. #include "nsHTMLTokens.h"
  48. #include "nsIHTMLContentSink.h"
  49. #include "nsDTDUtils.h"
  50. #include "nsParserNode.h"
  51. class nsIParserNode;
  52. class nsParser;
  53. class nsITokenizer;
  54. class nsCParserNode;
  55. class CIndirectTextToken : public CTextToken {
  56. public:
  57. CIndirectTextToken() : CTextToken() {
  58. mIndirectString=0;
  59. }
  60. void SetIndirectString(const nsSubstring& aString) {
  61. mIndirectString=&aString;
  62. }
  63. virtual const nsSubstring& GetStringValue(void){
  64. return (const nsSubstring&)*mIndirectString;
  65. }
  66. const nsSubstring* mIndirectString;
  67. };
  68. class CViewSourceHTML: public nsIDTD
  69. {
  70. public:
  71. NS_DECL_ISUPPORTS
  72. NS_DECL_NSIDTD
  73. CViewSourceHTML();
  74. virtual ~CViewSourceHTML();
  75. /**
  76. * Set this to TRUE if you want the DTD to verify its
  77. * context stack.
  78. * @update gess 7/23/98
  79. * @param
  80. * @return
  81. */
  82. virtual void SetVerification(bool aEnable);
  83. private:
  84. nsresult HandleToken(CToken* aToken);
  85. nsresult WriteTag(PRInt32 tagType,
  86. const nsSubstring &aText,
  87. PRInt32 attrCount,
  88. bool aTagInError);
  89. nsresult WriteAttributes(const nsAString& tagName,
  90. nsTokenAllocator* allocator, PRInt32 attrCount, bool aOwnerInError);
  91. void StartNewPreBlock(void);
  92. // Utility method for adding attributes to the nodes we generate
  93. void AddAttrToNode(nsCParserStartNode& aNode,
  94. nsTokenAllocator* aAllocator,
  95. const nsAString& aAttrName,
  96. const nsAString& aAttrValue);
  97. bool IsUrlAttribute(const nsAString& tagName,
  98. const nsAString& attrName, const nsAString& attrValue);
  99. void WriteHrefAttribute(nsTokenAllocator* allocator, const nsAString& href);
  100. nsresult CreateViewSourceURL(const nsAString& linkUrl, nsString& viewSourceUrl);
  101. void WriteTextInSpan(const nsAString& text, nsTokenAllocator* allocator,
  102. const nsAString& attrName, const nsAString& attrValue);
  103. void WriteTextInAnchor(const nsAString& text, nsTokenAllocator* allocator,
  104. const nsAString& attrName, const nsAString &attrValue);
  105. void WriteTextInElement(const nsAString& tagName, eHTMLTags tagType,
  106. const nsAString& text, nsTokenAllocator* allocator,
  107. const nsAString& attrName, const nsAString& attrValue);
  108. const nsDependentSubstring TrimTokenValue(const nsAString& tokenValue);
  109. void TrimTokenValue(nsAString::const_iterator& start,
  110. nsAString::const_iterator& end);
  111. bool IsTokenValueTrimmableCharacter(PRUnichar ch);
  112. nsresult GetBaseURI(nsIURI **result);
  113. nsresult SetBaseURI(const nsAString& baseSpec);
  114. static void ExpandEntities(const nsAString& textIn, nsString& textOut);
  115. static void CopyPossibleEntity(nsAString::const_iterator& iter,
  116. const nsAString::const_iterator& end,
  117. nsAString& textBuffer);
  118. static PRInt32 ToUnicode(const nsString &strNum, PRInt32 radix, PRInt32 fallback);
  119. protected:
  120. nsCString mCharset;
  121. nsIHTMLContentSink* mSink;
  122. PRInt32 mLineNumber;
  123. nsITokenizer* mTokenizer; // weak
  124. PRInt32 mTabSize;
  125. bool mSyntaxHighlight;
  126. bool mWrapLongLines;
  127. bool mHasOpenRoot;
  128. bool mHasOpenBody;
  129. nsDTDMode mDTDMode;
  130. eParserCommands mParserCommand; //tells us to viewcontent/viewsource/viewerrors...
  131. eParserDocType mDocType;
  132. nsCString mMimeType;
  133. nsString mFilename;
  134. nsCOMPtr<nsIURI> mBaseURI; // lazy -- always use GetBaseURI().
  135. PRUint32 mTokenCount;
  136. nsCParserStartNode mStartNode;
  137. nsCParserStartNode mTokenNode;
  138. CIndirectTextToken mITextToken;
  139. nsCParserStartNode mErrorNode;
  140. };
  141. #endif