|
1 /* |
|
2 * Copyright (c) 2009-2010 Mozilla Foundation |
|
3 * |
|
4 * Permission is hereby granted, free of charge, to any person obtaining a |
|
5 * copy of this software and associated documentation files (the "Software"), |
|
6 * to deal in the Software without restriction, including without limitation |
|
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
|
8 * and/or sell copies of the Software, and to permit persons to whom the |
|
9 * Software is furnished to do so, subject to the following conditions: |
|
10 * |
|
11 * The above copyright notice and this permission notice shall be included in |
|
12 * all copies or substantial portions of the Software. |
|
13 * |
|
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
|
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
|
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
|
17 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
|
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
|
19 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
|
20 * DEALINGS IN THE SOFTWARE. |
|
21 */ |
|
22 |
|
23 package nu.validator.htmlparser.impl; |
|
24 |
|
25 import nu.validator.htmlparser.annotation.Auto; |
|
26 |
|
27 |
|
28 public class StateSnapshot<T> implements TreeBuilderState<T> { |
|
29 |
|
30 private final @Auto StackNode<T>[] stack; |
|
31 |
|
32 private final @Auto StackNode<T>[] listOfActiveFormattingElements; |
|
33 |
|
34 private final @Auto int[] templateModeStack; |
|
35 |
|
36 private final T formPointer; |
|
37 |
|
38 private final T headPointer; |
|
39 |
|
40 private final T deepTreeSurrogateParent; |
|
41 |
|
42 private final int mode; |
|
43 |
|
44 private final int originalMode; |
|
45 |
|
46 private final boolean framesetOk; |
|
47 |
|
48 private final boolean needToDropLF; |
|
49 |
|
50 private final boolean quirks; |
|
51 |
|
52 /** |
|
53 * @param stack |
|
54 * @param listOfActiveFormattingElements |
|
55 * @param templateModeStack |
|
56 * @param formPointer |
|
57 * @param headPointer |
|
58 * @param deepTreeSurrogateParent |
|
59 * @param mode |
|
60 * @param originalMode |
|
61 * @param framesetOk |
|
62 * @param needToDropLF |
|
63 * @param quirks |
|
64 */ |
|
65 StateSnapshot(StackNode<T>[] stack, |
|
66 StackNode<T>[] listOfActiveFormattingElements, int[] templateModeStack, T formPointer, |
|
67 T headPointer, T deepTreeSurrogateParent, int mode, int originalMode, |
|
68 boolean framesetOk, boolean needToDropLF, boolean quirks) { |
|
69 this.stack = stack; |
|
70 this.listOfActiveFormattingElements = listOfActiveFormattingElements; |
|
71 this.templateModeStack = templateModeStack; |
|
72 this.formPointer = formPointer; |
|
73 this.headPointer = headPointer; |
|
74 this.deepTreeSurrogateParent = deepTreeSurrogateParent; |
|
75 this.mode = mode; |
|
76 this.originalMode = originalMode; |
|
77 this.framesetOk = framesetOk; |
|
78 this.needToDropLF = needToDropLF; |
|
79 this.quirks = quirks; |
|
80 } |
|
81 |
|
82 /** |
|
83 * @see nu.validator.htmlparser.impl.TreeBuilderState#getStack() |
|
84 */ |
|
85 public StackNode<T>[] getStack() { |
|
86 return stack; |
|
87 } |
|
88 |
|
89 /** |
|
90 * @see nu.validator.htmlparser.impl.TreeBuilderState#getTemplateModeStack() |
|
91 */ |
|
92 public int[] getTemplateModeStack() { |
|
93 return templateModeStack; |
|
94 } |
|
95 |
|
96 /** |
|
97 * @see nu.validator.htmlparser.impl.TreeBuilderState#getListOfActiveFormattingElements() |
|
98 */ |
|
99 public StackNode<T>[] getListOfActiveFormattingElements() { |
|
100 return listOfActiveFormattingElements; |
|
101 } |
|
102 |
|
103 /** |
|
104 * @see nu.validator.htmlparser.impl.TreeBuilderState#getFormPointer() |
|
105 */ |
|
106 public T getFormPointer() { |
|
107 return formPointer; |
|
108 } |
|
109 |
|
110 /** |
|
111 * Returns the headPointer. |
|
112 * |
|
113 * @return the headPointer |
|
114 */ |
|
115 public T getHeadPointer() { |
|
116 return headPointer; |
|
117 } |
|
118 |
|
119 /** |
|
120 * Returns the deepTreeSurrogateParent. |
|
121 * |
|
122 * @return the deepTreeSurrogateParent |
|
123 */ |
|
124 public T getDeepTreeSurrogateParent() { |
|
125 return deepTreeSurrogateParent; |
|
126 } |
|
127 |
|
128 /** |
|
129 * Returns the mode. |
|
130 * |
|
131 * @return the mode |
|
132 */ |
|
133 public int getMode() { |
|
134 return mode; |
|
135 } |
|
136 |
|
137 /** |
|
138 * Returns the originalMode. |
|
139 * |
|
140 * @return the originalMode |
|
141 */ |
|
142 public int getOriginalMode() { |
|
143 return originalMode; |
|
144 } |
|
145 |
|
146 /** |
|
147 * Returns the framesetOk. |
|
148 * |
|
149 * @return the framesetOk |
|
150 */ |
|
151 public boolean isFramesetOk() { |
|
152 return framesetOk; |
|
153 } |
|
154 |
|
155 /** |
|
156 * Returns the needToDropLF. |
|
157 * |
|
158 * @return the needToDropLF |
|
159 */ |
|
160 public boolean isNeedToDropLF() { |
|
161 return needToDropLF; |
|
162 } |
|
163 |
|
164 /** |
|
165 * Returns the quirks. |
|
166 * |
|
167 * @return the quirks |
|
168 */ |
|
169 public boolean isQuirks() { |
|
170 return quirks; |
|
171 } |
|
172 |
|
173 /** |
|
174 * @see nu.validator.htmlparser.impl.TreeBuilderState#getListOfActiveFormattingElementsLength() |
|
175 */ |
|
176 public int getListOfActiveFormattingElementsLength() { |
|
177 return listOfActiveFormattingElements.length; |
|
178 } |
|
179 |
|
180 /** |
|
181 * @see nu.validator.htmlparser.impl.TreeBuilderState#getStackLength() |
|
182 */ |
|
183 public int getStackLength() { |
|
184 return stack.length; |
|
185 } |
|
186 |
|
187 /** |
|
188 * @see nu.validator.htmlparser.impl.TreeBuilderState#getTemplateModeStackLength() |
|
189 */ |
|
190 public int getTemplateModeStackLength() { |
|
191 return templateModeStack.length; |
|
192 } |
|
193 |
|
194 @SuppressWarnings("unused") private void destructor() { |
|
195 for (int i = 0; i < stack.length; i++) { |
|
196 stack[i].release(); |
|
197 } |
|
198 for (int i = 0; i < listOfActiveFormattingElements.length; i++) { |
|
199 if (listOfActiveFormattingElements[i] != null) { |
|
200 listOfActiveFormattingElements[i].release(); |
|
201 } |
|
202 } |
|
203 } |
|
204 } |