nokogiri 1.11.1-java → 1.11.2-java

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of nokogiri might be problematic. Click here for more details.

Files changed (142) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE-DEPENDENCIES.md +12 -12
  3. data/LICENSE.md +1 -1
  4. data/README.md +20 -15
  5. data/ext/java/nokogiri/EncodingHandler.java +78 -59
  6. data/ext/java/nokogiri/HtmlDocument.java +137 -114
  7. data/ext/java/nokogiri/HtmlElementDescription.java +104 -87
  8. data/ext/java/nokogiri/HtmlEntityLookup.java +31 -26
  9. data/ext/java/nokogiri/HtmlSaxParserContext.java +220 -192
  10. data/ext/java/nokogiri/HtmlSaxPushParser.java +164 -139
  11. data/ext/java/nokogiri/NokogiriService.java +597 -526
  12. data/ext/java/nokogiri/XmlAttr.java +120 -96
  13. data/ext/java/nokogiri/XmlAttributeDecl.java +97 -76
  14. data/ext/java/nokogiri/XmlCdata.java +35 -26
  15. data/ext/java/nokogiri/XmlComment.java +48 -37
  16. data/ext/java/nokogiri/XmlDocument.java +642 -540
  17. data/ext/java/nokogiri/XmlDocumentFragment.java +127 -107
  18. data/ext/java/nokogiri/XmlDtd.java +450 -384
  19. data/ext/java/nokogiri/XmlElement.java +25 -18
  20. data/ext/java/nokogiri/XmlElementContent.java +345 -286
  21. data/ext/java/nokogiri/XmlElementDecl.java +126 -95
  22. data/ext/java/nokogiri/XmlEntityDecl.java +121 -97
  23. data/ext/java/nokogiri/XmlEntityReference.java +51 -42
  24. data/ext/java/nokogiri/XmlNamespace.java +177 -145
  25. data/ext/java/nokogiri/XmlNode.java +1843 -1588
  26. data/ext/java/nokogiri/XmlNodeSet.java +361 -299
  27. data/ext/java/nokogiri/XmlProcessingInstruction.java +49 -39
  28. data/ext/java/nokogiri/XmlReader.java +513 -418
  29. data/ext/java/nokogiri/XmlRelaxng.java +91 -78
  30. data/ext/java/nokogiri/XmlSaxParserContext.java +330 -285
  31. data/ext/java/nokogiri/XmlSaxPushParser.java +229 -190
  32. data/ext/java/nokogiri/XmlSchema.java +328 -263
  33. data/ext/java/nokogiri/XmlSyntaxError.java +113 -83
  34. data/ext/java/nokogiri/XmlText.java +57 -46
  35. data/ext/java/nokogiri/XmlXpathContext.java +240 -206
  36. data/ext/java/nokogiri/XsltStylesheet.java +282 -239
  37. data/ext/java/nokogiri/internals/ClosedStreamException.java +5 -2
  38. data/ext/java/nokogiri/internals/HtmlDomParserContext.java +199 -168
  39. data/ext/java/nokogiri/internals/IgnoreSchemaErrorsErrorHandler.java +17 -10
  40. data/ext/java/nokogiri/internals/NokogiriBlockingQueueInputStream.java +43 -16
  41. data/ext/java/nokogiri/internals/NokogiriDomParser.java +65 -50
  42. data/ext/java/nokogiri/internals/NokogiriEntityResolver.java +107 -88
  43. data/ext/java/nokogiri/internals/NokogiriErrorHandler.java +25 -18
  44. data/ext/java/nokogiri/internals/NokogiriHandler.java +316 -254
  45. data/ext/java/nokogiri/internals/NokogiriHelpers.java +738 -622
  46. data/ext/java/nokogiri/internals/NokogiriNamespaceCache.java +186 -143
  47. data/ext/java/nokogiri/internals/NokogiriNamespaceContext.java +83 -68
  48. data/ext/java/nokogiri/internals/NokogiriNonStrictErrorHandler.java +66 -49
  49. data/ext/java/nokogiri/internals/NokogiriNonStrictErrorHandler4NekoHtml.java +86 -69
  50. data/ext/java/nokogiri/internals/NokogiriStrictErrorHandler.java +44 -29
  51. data/ext/java/nokogiri/internals/NokogiriXPathFunction.java +118 -101
  52. data/ext/java/nokogiri/internals/NokogiriXPathFunctionResolver.java +34 -24
  53. data/ext/java/nokogiri/internals/NokogiriXPathVariableResolver.java +25 -17
  54. data/ext/java/nokogiri/internals/NokogiriXsltErrorListener.java +57 -42
  55. data/ext/java/nokogiri/internals/ParserContext.java +206 -179
  56. data/ext/java/nokogiri/internals/ReaderNode.java +478 -371
  57. data/ext/java/nokogiri/internals/SaveContextVisitor.java +822 -707
  58. data/ext/java/nokogiri/internals/SchemaErrorHandler.java +28 -19
  59. data/ext/java/nokogiri/internals/XalanDTMManagerPatch.java +129 -123
  60. data/ext/java/nokogiri/internals/XmlDeclHandler.java +5 -4
  61. data/ext/java/nokogiri/internals/XmlDomParserContext.java +208 -177
  62. data/ext/java/nokogiri/internals/XmlSaxParser.java +24 -17
  63. data/ext/java/nokogiri/internals/c14n/AttrCompare.java +71 -68
  64. data/ext/java/nokogiri/internals/c14n/C14nHelper.java +137 -118
  65. data/ext/java/nokogiri/internals/c14n/CanonicalFilter.java +27 -21
  66. data/ext/java/nokogiri/internals/c14n/CanonicalizationException.java +74 -61
  67. data/ext/java/nokogiri/internals/c14n/Canonicalizer.java +230 -205
  68. data/ext/java/nokogiri/internals/c14n/Canonicalizer11.java +572 -547
  69. data/ext/java/nokogiri/internals/c14n/Canonicalizer11_OmitComments.java +17 -10
  70. data/ext/java/nokogiri/internals/c14n/Canonicalizer11_WithComments.java +17 -10
  71. data/ext/java/nokogiri/internals/c14n/Canonicalizer20010315.java +323 -302
  72. data/ext/java/nokogiri/internals/c14n/Canonicalizer20010315Excl.java +232 -219
  73. data/ext/java/nokogiri/internals/c14n/Canonicalizer20010315ExclOmitComments.java +22 -15
  74. data/ext/java/nokogiri/internals/c14n/Canonicalizer20010315ExclWithComments.java +23 -16
  75. data/ext/java/nokogiri/internals/c14n/Canonicalizer20010315OmitComments.java +23 -16
  76. data/ext/java/nokogiri/internals/c14n/Canonicalizer20010315WithComments.java +22 -15
  77. data/ext/java/nokogiri/internals/c14n/CanonicalizerBase.java +575 -545
  78. data/ext/java/nokogiri/internals/c14n/CanonicalizerPhysical.java +141 -120
  79. data/ext/java/nokogiri/internals/c14n/CanonicalizerSpi.java +39 -38
  80. data/ext/java/nokogiri/internals/c14n/Constants.java +13 -10
  81. data/ext/java/nokogiri/internals/c14n/ElementProxy.java +279 -247
  82. data/ext/java/nokogiri/internals/c14n/HelperNodeList.java +66 -53
  83. data/ext/java/nokogiri/internals/c14n/IgnoreAllErrorHandler.java +44 -37
  84. data/ext/java/nokogiri/internals/c14n/InclusiveNamespaces.java +135 -120
  85. data/ext/java/nokogiri/internals/c14n/InvalidCanonicalizerException.java +59 -48
  86. data/ext/java/nokogiri/internals/c14n/NameSpaceSymbTable.java +384 -334
  87. data/ext/java/nokogiri/internals/c14n/NodeFilter.java +25 -24
  88. data/ext/java/nokogiri/internals/c14n/UtfHelpper.java +151 -140
  89. data/ext/java/nokogiri/internals/c14n/XMLUtils.java +456 -423
  90. data/ext/java/nokogiri/internals/dom2dtm/DOM2DTM.java +1466 -1500
  91. data/ext/java/nokogiri/internals/dom2dtm/DOM2DTMdefaultNamespaceDeclarationNode.java +626 -570
  92. data/ext/nokogiri/depend +34 -474
  93. data/ext/nokogiri/extconf.rb +253 -183
  94. data/ext/nokogiri/html_document.c +10 -15
  95. data/ext/nokogiri/html_element_description.c +84 -71
  96. data/ext/nokogiri/html_entity_lookup.c +21 -16
  97. data/ext/nokogiri/html_sax_parser_context.c +66 -65
  98. data/ext/nokogiri/html_sax_push_parser.c +29 -27
  99. data/ext/nokogiri/libxml2_backwards_compat.c +121 -0
  100. data/ext/nokogiri/nokogiri.c +171 -63
  101. data/ext/nokogiri/test_global_handlers.c +3 -4
  102. data/ext/nokogiri/xml_attr.c +15 -15
  103. data/ext/nokogiri/xml_attribute_decl.c +18 -18
  104. data/ext/nokogiri/xml_cdata.c +13 -18
  105. data/ext/nokogiri/xml_comment.c +19 -26
  106. data/ext/nokogiri/xml_document.c +221 -164
  107. data/ext/nokogiri/xml_document_fragment.c +13 -15
  108. data/ext/nokogiri/xml_dtd.c +54 -48
  109. data/ext/nokogiri/xml_element_content.c +30 -27
  110. data/ext/nokogiri/xml_element_decl.c +22 -22
  111. data/ext/nokogiri/xml_encoding_handler.c +17 -11
  112. data/ext/nokogiri/xml_entity_decl.c +32 -30
  113. data/ext/nokogiri/xml_entity_reference.c +16 -18
  114. data/ext/nokogiri/xml_namespace.c +56 -49
  115. data/ext/nokogiri/xml_node.c +338 -286
  116. data/ext/nokogiri/xml_node_set.c +168 -156
  117. data/ext/nokogiri/xml_processing_instruction.c +17 -19
  118. data/ext/nokogiri/xml_reader.c +191 -157
  119. data/ext/nokogiri/xml_relax_ng.c +29 -23
  120. data/ext/nokogiri/xml_sax_parser.c +117 -112
  121. data/ext/nokogiri/xml_sax_parser_context.c +100 -85
  122. data/ext/nokogiri/xml_sax_push_parser.c +34 -27
  123. data/ext/nokogiri/xml_schema.c +48 -42
  124. data/ext/nokogiri/xml_syntax_error.c +21 -23
  125. data/ext/nokogiri/xml_text.c +13 -17
  126. data/ext/nokogiri/xml_xpath_context.c +134 -127
  127. data/ext/nokogiri/xslt_stylesheet.c +157 -157
  128. data/lib/nokogiri.rb +1 -22
  129. data/lib/nokogiri/css/parser.rb +1 -1
  130. data/lib/nokogiri/extension.rb +26 -0
  131. data/lib/nokogiri/html/document_fragment.rb +15 -15
  132. data/lib/nokogiri/nokogiri.jar +0 -0
  133. data/lib/nokogiri/version/constant.rb +1 -1
  134. data/lib/nokogiri/version/info.rb +31 -8
  135. data/lib/nokogiri/xml/document.rb +31 -11
  136. data/lib/nokogiri/xml/node.rb +38 -42
  137. data/lib/nokogiri/xml/reader.rb +2 -9
  138. data/lib/nokogiri/xml/xpath.rb +1 -3
  139. data/lib/nokogiri/xml/xpath/syntax_error.rb +1 -1
  140. metadata +7 -8
  141. data/ext/nokogiri/xml_io.c +0 -63
  142. data/ext/nokogiri/xml_libxml2_hacks.c +0 -112
@@ -19,58 +19,69 @@
19
19
  package nokogiri.internals.c14n;
20
20
 
21
21
 
22
- public class InvalidCanonicalizerException extends Exception {
22
+ public class InvalidCanonicalizerException extends Exception
23
+ {
23
24
 
24
- /**
25
- *
26
- */
27
- private static final long serialVersionUID = 1L;
25
+ /**
26
+ *
27
+ */
28
+ private static final long serialVersionUID = 1L;
28
29
 
29
- /**
30
- * Constructor InvalidCanonicalizerException
31
- *
32
- */
33
- public InvalidCanonicalizerException() {
34
- super();
35
- }
30
+ /**
31
+ * Constructor InvalidCanonicalizerException
32
+ *
33
+ */
34
+ public
35
+ InvalidCanonicalizerException()
36
+ {
37
+ super();
38
+ }
36
39
 
37
- /**
38
- * Constructor InvalidCanonicalizerException
39
- *
40
- * @param message
41
- */
42
- public InvalidCanonicalizerException(String message) {
43
- super(message);
44
- }
40
+ /**
41
+ * Constructor InvalidCanonicalizerException
42
+ *
43
+ * @param message
44
+ */
45
+ public
46
+ InvalidCanonicalizerException(String message)
47
+ {
48
+ super(message);
49
+ }
45
50
 
46
- /**
47
- * Constructor InvalidCanonicalizerException
48
- *
49
- * @param message
50
- * @param exArgs
51
- */
52
- public InvalidCanonicalizerException(String message, Object... exArgs) {
53
- super(C14nHelper.getErrorMessage(message, exArgs));
54
- }
51
+ /**
52
+ * Constructor InvalidCanonicalizerException
53
+ *
54
+ * @param message
55
+ * @param exArgs
56
+ */
57
+ public
58
+ InvalidCanonicalizerException(String message, Object... exArgs)
59
+ {
60
+ super(C14nHelper.getErrorMessage(message, exArgs));
61
+ }
55
62
 
56
- /**
57
- * Constructor InvalidCanonicalizerException
58
- *
59
- * @param msgID
60
- * @param originalException
61
- */
62
- public InvalidCanonicalizerException(String message, Exception rootCause) {
63
- super(message, rootCause);
64
- }
63
+ /**
64
+ * Constructor InvalidCanonicalizerException
65
+ *
66
+ * @param msgID
67
+ * @param originalException
68
+ */
69
+ public
70
+ InvalidCanonicalizerException(String message, Exception rootCause)
71
+ {
72
+ super(message, rootCause);
73
+ }
65
74
 
66
- /**
67
- * Constructor InvalidCanonicalizerException
68
- *
69
- * @param msgID
70
- * @param exArgs
71
- * @param originalException
72
- */
73
- public InvalidCanonicalizerException(String message, Exception rootCause, Object... exArgs) {
74
- super(C14nHelper.getErrorMessage(message, exArgs), rootCause);
75
- }
75
+ /**
76
+ * Constructor InvalidCanonicalizerException
77
+ *
78
+ * @param msgID
79
+ * @param exArgs
80
+ * @param originalException
81
+ */
82
+ public
83
+ InvalidCanonicalizerException(String message, Exception rootCause, Object... exArgs)
84
+ {
85
+ super(C14nHelper.getErrorMessage(message, exArgs), rootCause);
86
+ }
76
87
  }
@@ -31,372 +31,422 @@ import org.w3c.dom.Node;
31
31
  * and at the same time in a list so it can be removed when the frame is pop back.
32
32
  * @author Raul Benito
33
33
  */
34
- public class NameSpaceSymbTable {
35
-
36
- private static final String XMLNS = "xmlns";
37
- private static final SymbMap initialMap = new SymbMap();
38
-
39
- static {
40
- NameSpaceSymbEntry ne = new NameSpaceSymbEntry("", null, true, XMLNS);
41
- ne.lastrendered = "";
42
- initialMap.put(XMLNS, ne);
43
- }
44
-
45
- /**The map betwen prefix-> entry table. */
46
- private SymbMap symb;
47
-
48
- /**The stacks for removing the definitions when doing pop.*/
49
- private List<SymbMap> level;
50
- private boolean cloned = true;
51
-
52
- /**
53
- * Default constractor
54
- **/
55
- public NameSpaceSymbTable() {
56
- level = new ArrayList<SymbMap>();
57
- //Insert the default binding for xmlns.
58
- symb = (SymbMap) initialMap.clone();
59
- }
34
+ public class NameSpaceSymbTable
35
+ {
36
+
37
+ private static final String XMLNS = "xmlns";
38
+ private static final SymbMap initialMap = new SymbMap();
39
+
40
+ static
41
+ {
42
+ NameSpaceSymbEntry ne = new NameSpaceSymbEntry("", null, true, XMLNS);
43
+ ne.lastrendered = "";
44
+ initialMap.put(XMLNS, ne);
45
+ }
46
+
47
+ /**The map betwen prefix-> entry table. */
48
+ private SymbMap symb;
49
+
50
+ /**The stacks for removing the definitions when doing pop.*/
51
+ private List<SymbMap> level;
52
+ private boolean cloned = true;
53
+
54
+ /**
55
+ * Default constractor
56
+ **/
57
+ public
58
+ NameSpaceSymbTable()
59
+ {
60
+ level = new ArrayList<SymbMap>();
61
+ //Insert the default binding for xmlns.
62
+ symb = (SymbMap) initialMap.clone();
63
+ }
64
+
65
+ /**
66
+ * Get all the unrendered nodes in the name space.
67
+ * For Inclusive rendering
68
+ * @param result the list where to fill the unrendered xmlns definitions.
69
+ **/
70
+ public void
71
+ getUnrenderedNodes(Collection<Attr> result)
72
+ {
73
+ Iterator<NameSpaceSymbEntry> it = symb.entrySet().iterator();
74
+ while (it.hasNext()) {
75
+ NameSpaceSymbEntry n = it.next();
76
+ //put them rendered?
77
+ if ((!n.rendered) && (n.n != null)) {
78
+ n = (NameSpaceSymbEntry) n.clone();
79
+ needsClone();
80
+ symb.put(n.prefix, n);
81
+ n.lastrendered = n.uri;
82
+ n.rendered = true;
60
83
 
61
- /**
62
- * Get all the unrendered nodes in the name space.
63
- * For Inclusive rendering
64
- * @param result the list where to fill the unrendered xmlns definitions.
65
- **/
66
- public void getUnrenderedNodes(Collection<Attr> result) {
67
- Iterator<NameSpaceSymbEntry> it = symb.entrySet().iterator();
68
- while (it.hasNext()) {
69
- NameSpaceSymbEntry n = it.next();
70
- //put them rendered?
71
- if ((!n.rendered) && (n.n != null)) {
72
- n = (NameSpaceSymbEntry) n.clone();
73
- needsClone();
74
- symb.put(n.prefix, n);
75
- n.lastrendered = n.uri;
76
- n.rendered = true;
77
-
78
- result.add(n.n);
79
- }
80
- }
84
+ result.add(n.n);
85
+ }
81
86
  }
82
-
83
- /**
84
- * Push a frame for visible namespace.
85
- * For Inclusive rendering.
86
- **/
87
- public void outputNodePush() {
88
- push();
87
+ }
88
+
89
+ /**
90
+ * Push a frame for visible namespace.
91
+ * For Inclusive rendering.
92
+ **/
93
+ public void
94
+ outputNodePush()
95
+ {
96
+ push();
97
+ }
98
+
99
+ /**
100
+ * Pop a frame for visible namespace.
101
+ **/
102
+ public void
103
+ outputNodePop()
104
+ {
105
+ pop();
106
+ }
107
+
108
+ /**
109
+ * Push a frame for a node.
110
+ * Inclusive or Exclusive.
111
+ **/
112
+ public void
113
+ push()
114
+ {
115
+ //Put the number of namespace definitions in the stack.
116
+ level.add(null);
117
+ cloned = false;
118
+ }
119
+
120
+ /**
121
+ * Pop a frame.
122
+ * Inclusive or Exclusive.
123
+ **/
124
+ public void
125
+ pop()
126
+ {
127
+ int size = level.size() - 1;
128
+ Object ob = level.remove(size);
129
+ if (ob != null) {
130
+ symb = (SymbMap)ob;
131
+ if (size == 0) {
132
+ cloned = false;
133
+ } else {
134
+ cloned = (level.get(size - 1) != symb);
135
+ }
136
+ } else {
137
+ cloned = false;
89
138
  }
90
-
91
- /**
92
- * Pop a frame for visible namespace.
93
- **/
94
- public void outputNodePop() {
95
- pop();
139
+ }
140
+
141
+ final void
142
+ needsClone()
143
+ {
144
+ if (!cloned) {
145
+ level.set(level.size() - 1, symb);
146
+ symb = (SymbMap) symb.clone();
147
+ cloned = true;
96
148
  }
97
-
98
- /**
99
- * Push a frame for a node.
100
- * Inclusive or Exclusive.
101
- **/
102
- public void push() {
103
- //Put the number of namespace definitions in the stack.
104
- level.add(null);
105
- cloned = false;
149
+ }
150
+
151
+
152
+ /**
153
+ * Gets the attribute node that defines the binding for the prefix.
154
+ * @param prefix the prefix to obtain the attribute.
155
+ * @return null if there is no need to render the prefix. Otherwise the node of
156
+ * definition.
157
+ **/
158
+ public Attr
159
+ getMapping(String prefix)
160
+ {
161
+ NameSpaceSymbEntry entry = symb.get(prefix);
162
+ if (entry == null) {
163
+ //There is no definition for the prefix(a bug?).
164
+ return null;
106
165
  }
107
-
108
- /**
109
- * Pop a frame.
110
- * Inclusive or Exclusive.
111
- **/
112
- public void pop() {
113
- int size = level.size() - 1;
114
- Object ob = level.remove(size);
115
- if (ob != null) {
116
- symb = (SymbMap)ob;
117
- if (size == 0) {
118
- cloned = false;
119
- } else {
120
- cloned = (level.get(size - 1) != symb);
121
- }
122
- } else {
123
- cloned = false;
124
- }
166
+ if (entry.rendered) {
167
+ //No need to render an entry already rendered.
168
+ return null;
125
169
  }
126
-
127
- final void needsClone() {
128
- if (!cloned) {
129
- level.set(level.size() - 1, symb);
130
- symb = (SymbMap) symb.clone();
131
- cloned = true;
132
- }
170
+ // Mark this entry as render.
171
+ entry = (NameSpaceSymbEntry) entry.clone();
172
+ needsClone();
173
+ symb.put(prefix, entry);
174
+ entry.rendered = true;
175
+ entry.lastrendered = entry.uri;
176
+ // Return the node for outputing.
177
+ return entry.n;
178
+ }
179
+
180
+ /**
181
+ * Gets a definition without mark it as render.
182
+ * For render in exclusive c14n the namespaces in the include prefixes.
183
+ * @param prefix The prefix whose definition is neaded.
184
+ * @return the attr to render, null if there is no need to render
185
+ **/
186
+ public Attr
187
+ getMappingWithoutRendered(String prefix)
188
+ {
189
+ NameSpaceSymbEntry entry = symb.get(prefix);
190
+ if (entry == null) {
191
+ return null;
133
192
  }
134
-
135
-
136
- /**
137
- * Gets the attribute node that defines the binding for the prefix.
138
- * @param prefix the prefix to obtain the attribute.
139
- * @return null if there is no need to render the prefix. Otherwise the node of
140
- * definition.
141
- **/
142
- public Attr getMapping(String prefix) {
143
- NameSpaceSymbEntry entry = symb.get(prefix);
144
- if (entry == null) {
145
- //There is no definition for the prefix(a bug?).
146
- return null;
147
- }
148
- if (entry.rendered) {
149
- //No need to render an entry already rendered.
150
- return null;
151
- }
152
- // Mark this entry as render.
153
- entry = (NameSpaceSymbEntry) entry.clone();
154
- needsClone();
155
- symb.put(prefix, entry);
156
- entry.rendered = true;
157
- entry.lastrendered = entry.uri;
158
- // Return the node for outputing.
159
- return entry.n;
193
+ if (entry.rendered) {
194
+ return null;
160
195
  }
161
-
162
- /**
163
- * Gets a definition without mark it as render.
164
- * For render in exclusive c14n the namespaces in the include prefixes.
165
- * @param prefix The prefix whose definition is neaded.
166
- * @return the attr to render, null if there is no need to render
167
- **/
168
- public Attr getMappingWithoutRendered(String prefix) {
169
- NameSpaceSymbEntry entry = symb.get(prefix);
170
- if (entry == null) {
171
- return null;
172
- }
173
- if (entry.rendered) {
174
- return null;
175
- }
176
- return entry.n;
196
+ return entry.n;
197
+ }
198
+
199
+ /**
200
+ * Adds the mapping for a prefix.
201
+ * @param prefix the prefix of definition
202
+ * @param uri the Uri of the definition
203
+ * @param n the attribute that have the definition
204
+ * @return true if there is already defined.
205
+ **/
206
+ public boolean
207
+ addMapping(String prefix, String uri, Attr n)
208
+ {
209
+ NameSpaceSymbEntry ob = symb.get(prefix);
210
+ if ((ob != null) && uri.equals(ob.uri)) {
211
+ //If we have it previously defined. Don't keep working.
212
+ return false;
177
213
  }
178
-
179
- /**
180
- * Adds the mapping for a prefix.
181
- * @param prefix the prefix of definition
182
- * @param uri the Uri of the definition
183
- * @param n the attribute that have the definition
184
- * @return true if there is already defined.
185
- **/
186
- public boolean addMapping(String prefix, String uri, Attr n) {
187
- NameSpaceSymbEntry ob = symb.get(prefix);
188
- if ((ob != null) && uri.equals(ob.uri)) {
189
- //If we have it previously defined. Don't keep working.
190
- return false;
191
- }
192
- //Creates and entry in the table for this new definition.
193
- NameSpaceSymbEntry ne = new NameSpaceSymbEntry(uri, n, false, prefix);
194
- needsClone();
195
- symb.put(prefix, ne);
196
- if (ob != null) {
197
- //We have a previous definition store it for the pop.
198
- //Check if a previous definition(not the inmidiatly one) has been rendered.
199
- ne.lastrendered = ob.lastrendered;
200
- if ((ob.lastrendered != null) && (ob.lastrendered.equals(uri))) {
201
- //Yes it is. Mark as rendered.
202
- ne.rendered = true;
203
- }
204
- }
205
- return true;
214
+ //Creates and entry in the table for this new definition.
215
+ NameSpaceSymbEntry ne = new NameSpaceSymbEntry(uri, n, false, prefix);
216
+ needsClone();
217
+ symb.put(prefix, ne);
218
+ if (ob != null) {
219
+ //We have a previous definition store it for the pop.
220
+ //Check if a previous definition(not the inmidiatly one) has been rendered.
221
+ ne.lastrendered = ob.lastrendered;
222
+ if ((ob.lastrendered != null) && (ob.lastrendered.equals(uri))) {
223
+ //Yes it is. Mark as rendered.
224
+ ne.rendered = true;
225
+ }
206
226
  }
207
-
208
- /**
209
- * Adds a definition and mark it as render.
210
- * For inclusive c14n.
211
- * @param prefix the prefix of definition
212
- * @param uri the Uri of the definition
213
- * @param n the attribute that have the definition
214
- * @return the attr to render, null if there is no need to render
215
- **/
216
- public Node addMappingAndRender(String prefix, String uri, Attr n) {
217
- NameSpaceSymbEntry ob = symb.get(prefix);
218
-
219
- if ((ob != null) && uri.equals(ob.uri)) {
220
- if (!ob.rendered) {
221
- ob = (NameSpaceSymbEntry) ob.clone();
222
- needsClone();
223
- symb.put(prefix, ob);
224
- ob.lastrendered = uri;
225
- ob.rendered = true;
226
- return ob.n;
227
- }
228
- return null;
229
- }
230
-
231
- NameSpaceSymbEntry ne = new NameSpaceSymbEntry(uri,n,true,prefix);
232
- ne.lastrendered = uri;
227
+ return true;
228
+ }
229
+
230
+ /**
231
+ * Adds a definition and mark it as render.
232
+ * For inclusive c14n.
233
+ * @param prefix the prefix of definition
234
+ * @param uri the Uri of the definition
235
+ * @param n the attribute that have the definition
236
+ * @return the attr to render, null if there is no need to render
237
+ **/
238
+ public Node
239
+ addMappingAndRender(String prefix, String uri, Attr n)
240
+ {
241
+ NameSpaceSymbEntry ob = symb.get(prefix);
242
+
243
+ if ((ob != null) && uri.equals(ob.uri)) {
244
+ if (!ob.rendered) {
245
+ ob = (NameSpaceSymbEntry) ob.clone();
233
246
  needsClone();
234
- symb.put(prefix, ne);
235
- if ((ob != null) && (ob.lastrendered != null) && (ob.lastrendered.equals(uri))) {
236
- ne.rendered = true;
237
- return null;
238
- }
239
- return ne.n;
247
+ symb.put(prefix, ob);
248
+ ob.lastrendered = uri;
249
+ ob.rendered = true;
250
+ return ob.n;
251
+ }
252
+ return null;
240
253
  }
241
254
 
242
- public int getLevel() {
243
- return level.size();
255
+ NameSpaceSymbEntry ne = new NameSpaceSymbEntry(uri, n, true, prefix);
256
+ ne.lastrendered = uri;
257
+ needsClone();
258
+ symb.put(prefix, ne);
259
+ if ((ob != null) && (ob.lastrendered != null) && (ob.lastrendered.equals(uri))) {
260
+ ne.rendered = true;
261
+ return null;
244
262
  }
245
-
246
- public void removeMapping(String prefix) {
247
- NameSpaceSymbEntry ob = symb.get(prefix);
248
-
249
- if (ob != null) {
250
- needsClone();
251
- symb.put(prefix, null);
252
- }
263
+ return ne.n;
264
+ }
265
+
266
+ public int
267
+ getLevel()
268
+ {
269
+ return level.size();
270
+ }
271
+
272
+ public void
273
+ removeMapping(String prefix)
274
+ {
275
+ NameSpaceSymbEntry ob = symb.get(prefix);
276
+
277
+ if (ob != null) {
278
+ needsClone();
279
+ symb.put(prefix, null);
253
280
  }
281
+ }
254
282
 
255
- public void removeMappingIfNotRender(String prefix) {
256
- NameSpaceSymbEntry ob = symb.get(prefix);
283
+ public void
284
+ removeMappingIfNotRender(String prefix)
285
+ {
286
+ NameSpaceSymbEntry ob = symb.get(prefix);
257
287
 
258
- if (ob != null && !ob.rendered) {
259
- needsClone();
260
- symb.put(prefix, null);
261
- }
288
+ if (ob != null && !ob.rendered) {
289
+ needsClone();
290
+ symb.put(prefix, null);
262
291
  }
292
+ }
263
293
 
264
- public boolean removeMappingIfRender(String prefix) {
265
- NameSpaceSymbEntry ob = symb.get(prefix);
294
+ public boolean
295
+ removeMappingIfRender(String prefix)
296
+ {
297
+ NameSpaceSymbEntry ob = symb.get(prefix);
266
298
 
267
- if (ob != null && ob.rendered) {
268
- needsClone();
269
- symb.put(prefix, null);
270
- }
271
- return false;
299
+ if (ob != null && ob.rendered) {
300
+ needsClone();
301
+ symb.put(prefix, null);
272
302
  }
303
+ return false;
304
+ }
273
305
  }
274
306
 
275
307
  /**
276
308
  * The internal structure of NameSpaceSymbTable.
277
309
  **/
278
- class NameSpaceSymbEntry implements Cloneable {
279
-
280
- String prefix;
281
-
282
- /**The URI that the prefix defines */
283
- String uri;
284
-
285
- /**The last output in the URI for this prefix (This for speed reason).*/
286
- String lastrendered = null;
287
-
288
- /**This prefix-URI has been already render or not.*/
289
- boolean rendered = false;
290
-
291
- /**The attribute to include.*/
292
- Attr n;
293
-
294
- NameSpaceSymbEntry(String name, Attr n, boolean rendered, String prefix) {
295
- this.uri = name;
296
- this.rendered = rendered;
297
- this.n = n;
298
- this.prefix = prefix;
299
- }
300
-
301
- /** @inheritDoc */
302
- public Object clone() {
303
- try {
304
- return super.clone();
305
- } catch (CloneNotSupportedException e) {
306
- return null;
307
- }
310
+ class NameSpaceSymbEntry implements Cloneable
311
+ {
312
+
313
+ String prefix;
314
+
315
+ /**The URI that the prefix defines */
316
+ String uri;
317
+
318
+ /**The last output in the URI for this prefix (This for speed reason).*/
319
+ String lastrendered = null;
320
+
321
+ /**This prefix-URI has been already render or not.*/
322
+ boolean rendered = false;
323
+
324
+ /**The attribute to include.*/
325
+ Attr n;
326
+
327
+ NameSpaceSymbEntry(String name, Attr n, boolean rendered, String prefix)
328
+ {
329
+ this.uri = name;
330
+ this.rendered = rendered;
331
+ this.n = n;
332
+ this.prefix = prefix;
333
+ }
334
+
335
+ /** @inheritDoc */
336
+ public Object
337
+ clone()
338
+ {
339
+ try {
340
+ return super.clone();
341
+ } catch (CloneNotSupportedException e) {
342
+ return null;
308
343
  }
344
+ }
309
345
  }
310
346
 
311
- class SymbMap implements Cloneable {
312
- int free = 23;
313
- NameSpaceSymbEntry[] entries;
314
- String[] keys;
315
-
316
- SymbMap() {
317
- entries = new NameSpaceSymbEntry[free];
318
- keys = new String[free];
347
+ class SymbMap implements Cloneable
348
+ {
349
+ int free = 23;
350
+ NameSpaceSymbEntry[] entries;
351
+ String[] keys;
352
+
353
+ SymbMap()
354
+ {
355
+ entries = new NameSpaceSymbEntry[free];
356
+ keys = new String[free];
357
+ }
358
+
359
+ void
360
+ put(String key, NameSpaceSymbEntry value)
361
+ {
362
+ int index = index(key);
363
+ Object oldKey = keys[index];
364
+ keys[index] = key;
365
+ entries[index] = value;
366
+ if ((oldKey == null || !oldKey.equals(key)) && (--free == 0)) {
367
+ free = entries.length;
368
+ int newCapacity = free << 2;
369
+ rehash(newCapacity);
319
370
  }
320
-
321
- void put(String key, NameSpaceSymbEntry value) {
322
- int index = index(key);
323
- Object oldKey = keys[index];
324
- keys[index] = key;
325
- entries[index] = value;
326
- if ((oldKey == null || !oldKey.equals(key)) && (--free == 0)) {
327
- free = entries.length;
328
- int newCapacity = free << 2;
329
- rehash(newCapacity);
330
- }
371
+ }
372
+
373
+ List<NameSpaceSymbEntry>
374
+ entrySet()
375
+ {
376
+ List<NameSpaceSymbEntry> a = new ArrayList<NameSpaceSymbEntry>();
377
+ for (int i = 0; i < entries.length; i++) {
378
+ if ((entries[i] != null) && !("".equals(entries[i].uri))) {
379
+ a.add(entries[i]);
380
+ }
331
381
  }
332
-
333
- List<NameSpaceSymbEntry> entrySet() {
334
- List<NameSpaceSymbEntry> a = new ArrayList<NameSpaceSymbEntry>();
335
- for (int i = 0;i < entries.length;i++) {
336
- if ((entries[i] != null) && !("".equals(entries[i].uri))) {
337
- a.add(entries[i]);
338
- }
339
- }
340
- return a;
382
+ return a;
383
+ }
384
+
385
+ protected int
386
+ index(Object obj)
387
+ {
388
+ Object[] set = keys;
389
+ int length = set.length;
390
+ //abs of index
391
+ int index = (obj.hashCode() & 0x7fffffff) % length;
392
+ Object cur = set[index];
393
+
394
+ if (cur == null || (cur.equals(obj))) {
395
+ return index;
341
396
  }
342
-
343
- protected int index(Object obj) {
344
- Object[] set = keys;
345
- int length = set.length;
346
- //abs of index
347
- int index = (obj.hashCode() & 0x7fffffff) % length;
348
- Object cur = set[index];
349
-
350
- if (cur == null || (cur.equals(obj))) {
351
- return index;
352
- }
353
- length--;
354
- do {
355
- index = index == length ? 0 : ++index;
356
- cur = set[index];
357
- } while (cur != null && (!cur.equals(obj)));
358
- return index;
359
- }
360
-
361
- /**
362
- * rehashes the map to the new capacity.
363
- *
364
- * @param newCapacity an <code>int</code> value
365
- */
366
- protected void rehash(int newCapacity) {
367
- int oldCapacity = keys.length;
368
- String oldKeys[] = keys;
369
- NameSpaceSymbEntry oldVals[] = entries;
370
-
371
- keys = new String[newCapacity];
372
- entries = new NameSpaceSymbEntry[newCapacity];
373
-
374
- for (int i = oldCapacity; i-- > 0;) {
375
- if (oldKeys[i] != null) {
376
- String o = oldKeys[i];
377
- int index = index(o);
378
- keys[index] = o;
379
- entries[index] = oldVals[i];
380
- }
381
- }
397
+ length--;
398
+ do {
399
+ index = index == length ? 0 : ++index;
400
+ cur = set[index];
401
+ } while (cur != null && (!cur.equals(obj)));
402
+ return index;
403
+ }
404
+
405
+ /**
406
+ * rehashes the map to the new capacity.
407
+ *
408
+ * @param newCapacity an <code>int</code> value
409
+ */
410
+ protected void
411
+ rehash(int newCapacity)
412
+ {
413
+ int oldCapacity = keys.length;
414
+ String oldKeys[] = keys;
415
+ NameSpaceSymbEntry oldVals[] = entries;
416
+
417
+ keys = new String[newCapacity];
418
+ entries = new NameSpaceSymbEntry[newCapacity];
419
+
420
+ for (int i = oldCapacity; i-- > 0;) {
421
+ if (oldKeys[i] != null) {
422
+ String o = oldKeys[i];
423
+ int index = index(o);
424
+ keys[index] = o;
425
+ entries[index] = oldVals[i];
426
+ }
382
427
  }
383
-
384
- NameSpaceSymbEntry get(String key) {
385
- return entries[index(key)];
386
- }
387
-
388
- protected Object clone() {
389
- try {
390
- SymbMap copy = (SymbMap) super.clone();
391
- copy.entries = new NameSpaceSymbEntry[entries.length];
392
- System.arraycopy(entries, 0, copy.entries, 0, entries.length);
393
- copy.keys = new String[keys.length];
394
- System.arraycopy(keys, 0, copy.keys, 0, keys.length);
395
-
396
- return copy;
397
- } catch (CloneNotSupportedException e) {
398
- e.printStackTrace();
399
- }
400
- return null;
428
+ }
429
+
430
+ NameSpaceSymbEntry
431
+ get(String key)
432
+ {
433
+ return entries[index(key)];
434
+ }
435
+
436
+ protected Object
437
+ clone()
438
+ {
439
+ try {
440
+ SymbMap copy = (SymbMap) super.clone();
441
+ copy.entries = new NameSpaceSymbEntry[entries.length];
442
+ System.arraycopy(entries, 0, copy.entries, 0, entries.length);
443
+ copy.keys = new String[keys.length];
444
+ System.arraycopy(keys, 0, copy.keys, 0, keys.length);
445
+
446
+ return copy;
447
+ } catch (CloneNotSupportedException e) {
448
+ e.printStackTrace();
401
449
  }
450
+ return null;
451
+ }
402
452
  }