nokogiri 1.11.0.rc3-java → 1.11.4-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 (187) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +3 -0
  3. data/LICENSE-DEPENDENCIES.md +1015 -947
  4. data/LICENSE.md +1 -1
  5. data/README.md +168 -91
  6. data/dependencies.yml +12 -12
  7. data/ext/java/nokogiri/EncodingHandler.java +76 -89
  8. data/ext/java/nokogiri/HtmlDocument.java +135 -144
  9. data/ext/java/nokogiri/HtmlElementDescription.java +102 -117
  10. data/ext/java/nokogiri/HtmlEntityLookup.java +33 -60
  11. data/ext/java/nokogiri/HtmlSaxParserContext.java +218 -222
  12. data/ext/java/nokogiri/HtmlSaxPushParser.java +162 -169
  13. data/ext/java/nokogiri/NokogiriService.java +595 -556
  14. data/ext/java/nokogiri/XmlAttr.java +118 -126
  15. data/ext/java/nokogiri/XmlAttributeDecl.java +95 -106
  16. data/ext/java/nokogiri/XmlCdata.java +35 -58
  17. data/ext/java/nokogiri/XmlComment.java +46 -67
  18. data/ext/java/nokogiri/XmlDocument.java +645 -572
  19. data/ext/java/nokogiri/XmlDocumentFragment.java +125 -137
  20. data/ext/java/nokogiri/XmlDtd.java +448 -414
  21. data/ext/java/nokogiri/XmlElement.java +23 -48
  22. data/ext/java/nokogiri/XmlElementContent.java +343 -316
  23. data/ext/java/nokogiri/XmlElementDecl.java +124 -125
  24. data/ext/java/nokogiri/XmlEntityDecl.java +119 -127
  25. data/ext/java/nokogiri/XmlEntityReference.java +49 -72
  26. data/ext/java/nokogiri/XmlNamespace.java +175 -175
  27. data/ext/java/nokogiri/XmlNode.java +1843 -1622
  28. data/ext/java/nokogiri/XmlNodeSet.java +361 -331
  29. data/ext/java/nokogiri/XmlProcessingInstruction.java +47 -69
  30. data/ext/java/nokogiri/XmlReader.java +513 -450
  31. data/ext/java/nokogiri/XmlRelaxng.java +89 -101
  32. data/ext/java/nokogiri/XmlSaxParserContext.java +328 -310
  33. data/ext/java/nokogiri/XmlSaxPushParser.java +227 -220
  34. data/ext/java/nokogiri/XmlSchema.java +335 -242
  35. data/ext/java/nokogiri/XmlSyntaxError.java +113 -119
  36. data/ext/java/nokogiri/XmlText.java +55 -76
  37. data/ext/java/nokogiri/XmlXpathContext.java +242 -210
  38. data/ext/java/nokogiri/XsltStylesheet.java +280 -269
  39. data/ext/java/nokogiri/internals/ClosedStreamException.java +5 -2
  40. data/ext/java/nokogiri/internals/HtmlDomParserContext.java +201 -190
  41. data/ext/java/nokogiri/internals/IgnoreSchemaErrorsErrorHandler.java +17 -10
  42. data/ext/java/nokogiri/internals/NokogiriBlockingQueueInputStream.java +43 -16
  43. data/ext/java/nokogiri/internals/NokogiriDomParser.java +63 -80
  44. data/ext/java/nokogiri/internals/NokogiriEntityResolver.java +107 -88
  45. data/ext/java/nokogiri/internals/NokogiriErrorHandler.java +27 -52
  46. data/ext/java/nokogiri/internals/NokogiriHandler.java +316 -286
  47. data/ext/java/nokogiri/internals/NokogiriHelpers.java +736 -652
  48. data/ext/java/nokogiri/internals/NokogiriNamespaceCache.java +184 -173
  49. data/ext/java/nokogiri/internals/NokogiriNamespaceContext.java +79 -89
  50. data/ext/java/nokogiri/internals/NokogiriNonStrictErrorHandler.java +64 -79
  51. data/ext/java/nokogiri/internals/NokogiriNonStrictErrorHandler4NekoHtml.java +84 -99
  52. data/ext/java/nokogiri/internals/NokogiriStrictErrorHandler.java +48 -65
  53. data/ext/java/nokogiri/internals/NokogiriXPathFunction.java +119 -78
  54. data/ext/java/nokogiri/internals/NokogiriXPathFunctionResolver.java +34 -54
  55. data/ext/java/nokogiri/internals/NokogiriXPathVariableResolver.java +23 -46
  56. data/ext/java/nokogiri/internals/NokogiriXsltErrorListener.java +55 -72
  57. data/ext/java/nokogiri/internals/ParserContext.java +206 -211
  58. data/ext/java/nokogiri/internals/ReaderNode.java +478 -403
  59. data/ext/java/nokogiri/internals/SaveContextVisitor.java +822 -739
  60. data/ext/java/nokogiri/internals/SchemaErrorHandler.java +31 -54
  61. data/ext/java/nokogiri/internals/XalanDTMManagerPatch.java +129 -123
  62. data/ext/java/nokogiri/internals/XmlDeclHandler.java +3 -34
  63. data/ext/java/nokogiri/internals/XmlDomParserContext.java +206 -207
  64. data/ext/java/nokogiri/internals/XmlSaxParser.java +22 -47
  65. data/ext/java/nokogiri/internals/c14n/AttrCompare.java +71 -68
  66. data/ext/java/nokogiri/internals/c14n/C14nHelper.java +137 -118
  67. data/ext/java/nokogiri/internals/c14n/CanonicalFilter.java +27 -21
  68. data/ext/java/nokogiri/internals/c14n/CanonicalizationException.java +74 -61
  69. data/ext/java/nokogiri/internals/c14n/Canonicalizer.java +230 -205
  70. data/ext/java/nokogiri/internals/c14n/Canonicalizer11.java +572 -547
  71. data/ext/java/nokogiri/internals/c14n/Canonicalizer11_OmitComments.java +17 -10
  72. data/ext/java/nokogiri/internals/c14n/Canonicalizer11_WithComments.java +17 -10
  73. data/ext/java/nokogiri/internals/c14n/Canonicalizer20010315.java +323 -302
  74. data/ext/java/nokogiri/internals/c14n/Canonicalizer20010315Excl.java +232 -219
  75. data/ext/java/nokogiri/internals/c14n/Canonicalizer20010315ExclOmitComments.java +22 -15
  76. data/ext/java/nokogiri/internals/c14n/Canonicalizer20010315ExclWithComments.java +23 -16
  77. data/ext/java/nokogiri/internals/c14n/Canonicalizer20010315OmitComments.java +23 -16
  78. data/ext/java/nokogiri/internals/c14n/Canonicalizer20010315WithComments.java +22 -15
  79. data/ext/java/nokogiri/internals/c14n/CanonicalizerBase.java +575 -545
  80. data/ext/java/nokogiri/internals/c14n/CanonicalizerPhysical.java +141 -120
  81. data/ext/java/nokogiri/internals/c14n/CanonicalizerSpi.java +39 -38
  82. data/ext/java/nokogiri/internals/c14n/Constants.java +13 -10
  83. data/ext/java/nokogiri/internals/c14n/ElementProxy.java +279 -247
  84. data/ext/java/nokogiri/internals/c14n/HelperNodeList.java +66 -53
  85. data/ext/java/nokogiri/internals/c14n/IgnoreAllErrorHandler.java +44 -37
  86. data/ext/java/nokogiri/internals/c14n/InclusiveNamespaces.java +135 -120
  87. data/ext/java/nokogiri/internals/c14n/InvalidCanonicalizerException.java +59 -48
  88. data/ext/java/nokogiri/internals/c14n/NameSpaceSymbTable.java +384 -334
  89. data/ext/java/nokogiri/internals/c14n/NodeFilter.java +25 -24
  90. data/ext/java/nokogiri/internals/c14n/UtfHelpper.java +151 -140
  91. data/ext/java/nokogiri/internals/c14n/XMLUtils.java +456 -423
  92. data/ext/java/nokogiri/internals/dom2dtm/DOM2DTM.java +1466 -1500
  93. data/ext/java/nokogiri/internals/dom2dtm/DOM2DTMdefaultNamespaceDeclarationNode.java +626 -574
  94. data/ext/nokogiri/depend +37 -358
  95. data/ext/nokogiri/extconf.rb +581 -374
  96. data/ext/nokogiri/html_document.c +78 -82
  97. data/ext/nokogiri/html_element_description.c +84 -71
  98. data/ext/nokogiri/html_entity_lookup.c +21 -16
  99. data/ext/nokogiri/html_sax_parser_context.c +69 -66
  100. data/ext/nokogiri/html_sax_push_parser.c +42 -34
  101. data/ext/nokogiri/libxml2_backwards_compat.c +121 -0
  102. data/ext/nokogiri/nokogiri.c +192 -93
  103. data/ext/nokogiri/test_global_handlers.c +40 -0
  104. data/ext/nokogiri/xml_attr.c +15 -15
  105. data/ext/nokogiri/xml_attribute_decl.c +18 -18
  106. data/ext/nokogiri/xml_cdata.c +13 -18
  107. data/ext/nokogiri/xml_comment.c +19 -26
  108. data/ext/nokogiri/xml_document.c +246 -188
  109. data/ext/nokogiri/xml_document_fragment.c +13 -15
  110. data/ext/nokogiri/xml_dtd.c +54 -48
  111. data/ext/nokogiri/xml_element_content.c +30 -27
  112. data/ext/nokogiri/xml_element_decl.c +22 -22
  113. data/ext/nokogiri/xml_encoding_handler.c +17 -11
  114. data/ext/nokogiri/xml_entity_decl.c +32 -30
  115. data/ext/nokogiri/xml_entity_reference.c +16 -18
  116. data/ext/nokogiri/xml_namespace.c +56 -49
  117. data/ext/nokogiri/xml_node.c +371 -320
  118. data/ext/nokogiri/xml_node_set.c +168 -156
  119. data/ext/nokogiri/xml_processing_instruction.c +17 -19
  120. data/ext/nokogiri/xml_reader.c +191 -157
  121. data/ext/nokogiri/xml_relax_ng.c +52 -28
  122. data/ext/nokogiri/xml_sax_parser.c +118 -118
  123. data/ext/nokogiri/xml_sax_parser_context.c +103 -86
  124. data/ext/nokogiri/xml_sax_push_parser.c +36 -27
  125. data/ext/nokogiri/xml_schema.c +95 -47
  126. data/ext/nokogiri/xml_syntax_error.c +42 -21
  127. data/ext/nokogiri/xml_text.c +13 -17
  128. data/ext/nokogiri/xml_xpath_context.c +206 -123
  129. data/ext/nokogiri/xslt_stylesheet.c +158 -161
  130. data/lib/nokogiri.rb +3 -7
  131. data/lib/nokogiri/css/parser.rb +3 -3
  132. data/lib/nokogiri/css/parser.y +2 -2
  133. data/lib/nokogiri/css/xpath_visitor.rb +70 -42
  134. data/lib/nokogiri/extension.rb +26 -0
  135. data/lib/nokogiri/html/document.rb +12 -26
  136. data/lib/nokogiri/html/document_fragment.rb +15 -15
  137. data/lib/nokogiri/nokogiri.jar +0 -0
  138. data/lib/nokogiri/version.rb +2 -149
  139. data/lib/nokogiri/version/constant.rb +5 -0
  140. data/lib/nokogiri/version/info.rb +205 -0
  141. data/lib/nokogiri/xml/document.rb +91 -35
  142. data/lib/nokogiri/xml/document_fragment.rb +4 -6
  143. data/lib/nokogiri/xml/node.rb +89 -69
  144. data/lib/nokogiri/xml/parse_options.rb +6 -0
  145. data/lib/nokogiri/xml/reader.rb +2 -9
  146. data/lib/nokogiri/xml/relax_ng.rb +6 -2
  147. data/lib/nokogiri/xml/schema.rb +12 -4
  148. data/lib/nokogiri/xml/searchable.rb +3 -1
  149. data/lib/nokogiri/xml/xpath.rb +1 -3
  150. data/lib/nokogiri/xml/xpath/syntax_error.rb +1 -1
  151. metadata +86 -177
  152. data/ext/nokogiri/html_document.h +0 -10
  153. data/ext/nokogiri/html_element_description.h +0 -10
  154. data/ext/nokogiri/html_entity_lookup.h +0 -8
  155. data/ext/nokogiri/html_sax_parser_context.h +0 -11
  156. data/ext/nokogiri/html_sax_push_parser.h +0 -9
  157. data/ext/nokogiri/nokogiri.h +0 -134
  158. data/ext/nokogiri/xml_attr.h +0 -9
  159. data/ext/nokogiri/xml_attribute_decl.h +0 -9
  160. data/ext/nokogiri/xml_cdata.h +0 -9
  161. data/ext/nokogiri/xml_comment.h +0 -9
  162. data/ext/nokogiri/xml_document.h +0 -23
  163. data/ext/nokogiri/xml_document_fragment.h +0 -10
  164. data/ext/nokogiri/xml_dtd.h +0 -10
  165. data/ext/nokogiri/xml_element_content.h +0 -10
  166. data/ext/nokogiri/xml_element_decl.h +0 -9
  167. data/ext/nokogiri/xml_encoding_handler.h +0 -8
  168. data/ext/nokogiri/xml_entity_decl.h +0 -10
  169. data/ext/nokogiri/xml_entity_reference.h +0 -9
  170. data/ext/nokogiri/xml_io.c +0 -63
  171. data/ext/nokogiri/xml_io.h +0 -11
  172. data/ext/nokogiri/xml_libxml2_hacks.c +0 -112
  173. data/ext/nokogiri/xml_libxml2_hacks.h +0 -12
  174. data/ext/nokogiri/xml_namespace.h +0 -14
  175. data/ext/nokogiri/xml_node.h +0 -13
  176. data/ext/nokogiri/xml_node_set.h +0 -12
  177. data/ext/nokogiri/xml_processing_instruction.h +0 -9
  178. data/ext/nokogiri/xml_reader.h +0 -10
  179. data/ext/nokogiri/xml_relax_ng.h +0 -9
  180. data/ext/nokogiri/xml_sax_parser.h +0 -39
  181. data/ext/nokogiri/xml_sax_parser_context.h +0 -10
  182. data/ext/nokogiri/xml_sax_push_parser.h +0 -9
  183. data/ext/nokogiri/xml_schema.h +0 -9
  184. data/ext/nokogiri/xml_syntax_error.h +0 -13
  185. data/ext/nokogiri/xml_text.h +0 -9
  186. data/ext/nokogiri/xml_xpath_context.h +0 -10
  187. data/ext/nokogiri/xslt_stylesheet.h +0 -14
@@ -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
  }