1 | /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
---|
2 | /* ***** BEGIN LICENSE BLOCK ***** |
---|
3 | * Version: NPL 1.1/GPL 2.0/LGPL 2.1 |
---|
4 | * |
---|
5 | * The contents of this file are subject to the Netscape Public License |
---|
6 | * Version 1.1 (the "License"); you may not use this file except in |
---|
7 | * compliance with the License. You may obtain a copy of the License at |
---|
8 | * http://www.mozilla.org/NPL/ |
---|
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 | * |
---|
25 | * Alternatively, the contents of this file may be used under the terms of |
---|
26 | * either the GNU General Public License Version 2 or later (the "GPL"), or |
---|
27 | * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), |
---|
28 | * in which case the provisions of the GPL or the LGPL are applicable instead |
---|
29 | * of those above. If you wish to allow use of your version of this file only |
---|
30 | * under the terms of either the GPL or the LGPL, and not to allow others to |
---|
31 | * use your version of this file under the terms of the NPL, indicate your |
---|
32 | * decision by deleting the provisions above and replace them with the notice |
---|
33 | * and other provisions required by the GPL or the LGPL. If you do not delete |
---|
34 | * the provisions above, a recipient may use your version of this file under |
---|
35 | * the terms of any one of the NPL, the GPL or the LGPL. |
---|
36 | * |
---|
37 | * ***** END LICENSE BLOCK ***** */ |
---|
38 | |
---|
39 | |
---|
40 | /** |
---|
41 | * MODULE NOTES: |
---|
42 | * @update gess 4/1/98 |
---|
43 | * |
---|
44 | * This class is defines the basic interface between the |
---|
45 | * parser and the content sink. The parser will iterate |
---|
46 | * over the collection of tokens that it sees from the |
---|
47 | * tokenizer, coverting each related "group" into one of |
---|
48 | * these. This object gets passed to the sink, and is |
---|
49 | * then immediately reused. |
---|
50 | * |
---|
51 | * If you want to hang onto one of these, you should |
---|
52 | * make your own copy. |
---|
53 | * |
---|
54 | */ |
---|
55 | |
---|
56 | #ifndef NS_IPARSERNODE__ |
---|
57 | #define NS_IPARSERNODE__ |
---|
58 | |
---|
59 | #include "nsISupports.h" |
---|
60 | #include "prtypes.h" |
---|
61 | #include "nsString.h" |
---|
62 | #include "nsDebug.h" |
---|
63 | |
---|
64 | //#define HEAP_ALLOCATED_NODES |
---|
65 | //#define DEBUG_TRACK_NODES |
---|
66 | |
---|
67 | class nsIAtom; |
---|
68 | class CToken; |
---|
69 | |
---|
70 | // 6e59f160-2717-11d2-9246-00805f8a7ab6 |
---|
71 | #define NS_IPARSER_NODE_IID \ |
---|
72 | {0x6e59f160, 0x2717, 0x11d1, \ |
---|
73 | {0x92, 0x46, 0x00, 0x80, 0x5f, 0x8a, 0x7a, 0xb6}} |
---|
74 | |
---|
75 | /** |
---|
76 | * Parser nodes are the unit of exchange between the |
---|
77 | * parser and the content sink. Nodes offer access to |
---|
78 | * the current token, its attributes, and its skipped- |
---|
79 | * content if applicable. |
---|
80 | * |
---|
81 | * @update gess 3/25/98 |
---|
82 | */ |
---|
83 | class nsIParserNode { // XXX Should be nsAParserNode |
---|
84 | |
---|
85 | public: |
---|
86 | |
---|
87 | |
---|
88 | /** |
---|
89 | * Retrieve the name of the node |
---|
90 | * @update gess5/11/98 |
---|
91 | * @return string containing node name |
---|
92 | */ |
---|
93 | virtual const nsAString& GetTagName() const = 0; //to get name of tag |
---|
94 | |
---|
95 | /** |
---|
96 | * Retrieve the text from the given node |
---|
97 | * @update gess5/11/98 |
---|
98 | * @return string containing node text |
---|
99 | */ |
---|
100 | virtual const nsAString& GetText() const = 0; //get plain text if available |
---|
101 | |
---|
102 | /** |
---|
103 | * Retrieve the type of the parser node. |
---|
104 | * @update gess5/11/98 |
---|
105 | * @return node type. |
---|
106 | */ |
---|
107 | virtual PRInt32 GetNodeType() const =0; |
---|
108 | |
---|
109 | /** |
---|
110 | * Retrieve token type of parser node |
---|
111 | * @update gess5/11/98 |
---|
112 | * @return token type |
---|
113 | */ |
---|
114 | virtual PRInt32 GetTokenType() const =0; |
---|
115 | |
---|
116 | /** |
---|
117 | * Retrieve the number of attributes in this node. |
---|
118 | * @update gess5/11/98 |
---|
119 | * @return count of attributes (may be 0) |
---|
120 | */ |
---|
121 | virtual PRInt32 GetAttributeCount(PRBool askToken=PR_FALSE) const =0; |
---|
122 | |
---|
123 | /** |
---|
124 | * Retrieve the key (of key/value pair) at given index |
---|
125 | * @update gess5/11/98 |
---|
126 | * @param anIndex is the index of the key you want |
---|
127 | * @return string containing key. |
---|
128 | */ |
---|
129 | virtual const nsAString& GetKeyAt(PRUint32 anIndex) const = 0; |
---|
130 | |
---|
131 | /** |
---|
132 | * Retrieve the value (of key/value pair) at given index |
---|
133 | * @update gess5/11/98 |
---|
134 | * @param anIndex is the index of the value you want |
---|
135 | * @return string containing value. |
---|
136 | */ |
---|
137 | virtual const nsAString& GetValueAt(PRUint32 anIndex) const = 0; |
---|
138 | |
---|
139 | /** |
---|
140 | * NOTE: When the node is an entity, this will translate the entity |
---|
141 | * to it's unicode value, and store it in aString. |
---|
142 | * @update gess5/11/98 |
---|
143 | * @param aString will contain the resulting unicode string value |
---|
144 | * @return int (unicode char or unicode index from table) |
---|
145 | */ |
---|
146 | virtual PRInt32 TranslateToUnicodeStr(nsString& aString) const = 0; |
---|
147 | |
---|
148 | |
---|
149 | virtual void AddAttribute(CToken* aToken)=0; |
---|
150 | |
---|
151 | /** |
---|
152 | * This getter retrieves the line number from the input source where |
---|
153 | * the token occured. Lines are interpreted as occuring between \n characters. |
---|
154 | * @update gess7/24/98 |
---|
155 | * @return int containing the line number the token was found on |
---|
156 | */ |
---|
157 | virtual PRInt32 GetSourceLineNumber(void) const =0; |
---|
158 | |
---|
159 | /** |
---|
160 | * This pair of methods allows us to set a generic bit (for arbitrary use) |
---|
161 | * on each node stored in the context. |
---|
162 | * @update gess 11May2000 |
---|
163 | */ |
---|
164 | virtual PRBool GetGenericState(void) const =0; |
---|
165 | virtual void SetGenericState(PRBool aState) =0; |
---|
166 | |
---|
167 | /** Retrieve a string containing the tag and its attributes in "source" form |
---|
168 | * @update rickg 06June2000 |
---|
169 | * @return void |
---|
170 | */ |
---|
171 | virtual void GetSource(nsString& aString)=0; |
---|
172 | |
---|
173 | /** Release all the objects you're holding |
---|
174 | * @update harishd 08/02/00 |
---|
175 | * @return void |
---|
176 | */ |
---|
177 | virtual nsresult ReleaseAll()=0; |
---|
178 | }; |
---|
179 | |
---|
180 | #endif |
---|