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
@@ -43,131 +43,152 @@ import org.w3c.dom.ProcessingInstruction;
43
43
  * because the decrypted XML content will share the same physical representation
44
44
  * as the original XML content that was encrypted.
45
45
  */
46
- public class CanonicalizerPhysical extends CanonicalizerBase {
47
-
48
- private final SortedSet<Attr> result = new TreeSet<Attr>(COMPARE);
49
-
50
- /**
51
- * Constructor Canonicalizer20010315
52
- */
53
- public CanonicalizerPhysical() {
54
- super(true);
55
- }
56
-
57
- /**
58
- * Always throws a CanonicalizationException.
59
- *
60
- * @param xpathNodeSet
61
- * @param inclusiveNamespaces
62
- * @return none it always fails
63
- * @throws CanonicalizationException always
64
- */
65
- public byte[] engineCanonicalizeXPathNodeSet(Set<Node> xpathNodeSet, String inclusiveNamespaces, CanonicalFilter filter)
66
- throws CanonicalizationException {
67
-
68
- /** $todo$ well, should we throw UnsupportedOperationException ? */
69
- throw new CanonicalizationException("c14n.Canonicalizer.UnsupportedOperation");
46
+ public class CanonicalizerPhysical extends CanonicalizerBase
47
+ {
48
+
49
+ private final SortedSet<Attr> result = new TreeSet<Attr>(COMPARE);
50
+
51
+ /**
52
+ * Constructor Canonicalizer20010315
53
+ */
54
+ public
55
+ CanonicalizerPhysical()
56
+ {
57
+ super(true);
58
+ }
59
+
60
+ /**
61
+ * Always throws a CanonicalizationException.
62
+ *
63
+ * @param xpathNodeSet
64
+ * @param inclusiveNamespaces
65
+ * @return none it always fails
66
+ * @throws CanonicalizationException always
67
+ */
68
+ public byte[]
69
+ engineCanonicalizeXPathNodeSet(Set<Node> xpathNodeSet, String inclusiveNamespaces, CanonicalFilter filter)
70
+ throws CanonicalizationException
71
+ {
72
+
73
+ /** $todo$ well, should we throw UnsupportedOperationException ? */
74
+ throw new CanonicalizationException("c14n.Canonicalizer.UnsupportedOperation");
75
+ }
76
+
77
+ /**
78
+ * Always throws a CanonicalizationException.
79
+ *
80
+ * @param rootNode
81
+ * @param inclusiveNamespaces
82
+ * @return none it always fails
83
+ * @throws CanonicalizationException
84
+ */
85
+ @Override
86
+ public byte[]
87
+ engineCanonicalizeSubTree(Node rootNode, String inclusiveNamespaces, CanonicalFilter filter)
88
+ throws CanonicalizationException
89
+ {
90
+
91
+ /** $todo$ well, should we throw UnsupportedOperationException ? */
92
+ throw new CanonicalizationException("c14n.Canonicalizer.UnsupportedOperation");
93
+ }
94
+
95
+ /**
96
+ * Returns the Attr[]s to be output for the given element.
97
+ * <br>
98
+ * The code of this method is a copy of {@link #handleAttributes(Element,
99
+ * NameSpaceSymbTable)},
100
+ * whereas it takes into account that subtree-c14n is -- well -- subtree-based.
101
+ * So if the element in question isRoot of c14n, it's parent is not in the
102
+ * node set, as well as all other ancestors.
103
+ *
104
+ * @param element
105
+ * @param ns
106
+ * @return the Attr[]s to be output
107
+ * @throws CanonicalizationException
108
+ */
109
+ @Override
110
+ protected Iterator<Attr>
111
+ handleAttributesSubtree(Element element, NameSpaceSymbTable ns)
112
+ throws CanonicalizationException
113
+ {
114
+ if (!element.hasAttributes()) {
115
+ return null;
70
116
  }
71
117
 
72
- /**
73
- * Always throws a CanonicalizationException.
74
- *
75
- * @param rootNode
76
- * @param inclusiveNamespaces
77
- * @return none it always fails
78
- * @throws CanonicalizationException
79
- */
80
- @Override
81
- public byte[] engineCanonicalizeSubTree(Node rootNode, String inclusiveNamespaces, CanonicalFilter filter)
82
- throws CanonicalizationException {
83
-
84
- /** $todo$ well, should we throw UnsupportedOperationException ? */
85
- throw new CanonicalizationException("c14n.Canonicalizer.UnsupportedOperation");
86
- }
87
-
88
- /**
89
- * Returns the Attr[]s to be output for the given element.
90
- * <br>
91
- * The code of this method is a copy of {@link #handleAttributes(Element,
92
- * NameSpaceSymbTable)},
93
- * whereas it takes into account that subtree-c14n is -- well -- subtree-based.
94
- * So if the element in question isRoot of c14n, it's parent is not in the
95
- * node set, as well as all other ancestors.
96
- *
97
- * @param element
98
- * @param ns
99
- * @return the Attr[]s to be output
100
- * @throws CanonicalizationException
101
- */
102
- @Override
103
- protected Iterator<Attr> handleAttributesSubtree(Element element, NameSpaceSymbTable ns)
104
- throws CanonicalizationException {
105
- if (!element.hasAttributes()) {
106
- return null;
107
- }
108
-
109
- // result will contain all the attrs declared directly on that element
110
- final SortedSet<Attr> result = this.result;
111
- result.clear();
112
-
113
- if (element.hasAttributes()) {
114
- NamedNodeMap attrs = element.getAttributes();
115
- int attrsLength = attrs.getLength();
116
-
117
- for (int i = 0; i < attrsLength; i++) {
118
- Attr attribute = (Attr) attrs.item(i);
119
- result.add(attribute);
120
- }
121
- }
122
-
123
- return result.iterator();
124
- }
118
+ // result will contain all the attrs declared directly on that element
119
+ final SortedSet<Attr> result = this.result;
120
+ result.clear();
125
121
 
126
- /**
127
- * Returns the Attr[]s to be output for the given element.
128
- *
129
- * @param element
130
- * @param ns
131
- * @return the Attr[]s to be output
132
- * @throws CanonicalizationException
133
- */
134
- @Override
135
- protected Iterator<Attr> handleAttributes(Element element, NameSpaceSymbTable ns)
136
- throws CanonicalizationException {
137
-
138
- /** $todo$ well, should we throw UnsupportedOperationException ? */
139
- throw new CanonicalizationException("c14n.Canonicalizer.UnsupportedOperation");
140
- }
122
+ if (element.hasAttributes()) {
123
+ NamedNodeMap attrs = element.getAttributes();
124
+ int attrsLength = attrs.getLength();
141
125
 
142
- @Override
143
- protected void handleParent(Element e, NameSpaceSymbTable ns) {
144
- // nothing to do
126
+ for (int i = 0; i < attrsLength; i++) {
127
+ Attr attribute = (Attr) attrs.item(i);
128
+ result.add(attribute);
129
+ }
145
130
  }
146
131
 
147
- /** @inheritDoc */
148
- @Override
149
- public final String engineGetURI() {
150
- return Canonicalizer.ALGO_ID_C14N_PHYSICAL;
151
- }
152
-
153
- /** @inheritDoc */
154
- @Override
155
- public final boolean engineGetIncludeComments() {
156
- return true;
157
- }
158
-
159
- @Override
160
- protected void outputPItoWriter(ProcessingInstruction currentPI,
161
- OutputStream writer, int position) throws IOException {
162
- // Processing Instructions before or after the document element are not treated specially
163
- super.outputPItoWriter(currentPI, writer, NODE_NOT_BEFORE_OR_AFTER_DOCUMENT_ELEMENT);
164
- }
165
-
166
- @Override
167
- protected void outputCommentToWriter(Comment currentComment,
168
- OutputStream writer, int position) throws IOException {
169
- // Comments before or after the document element are not treated specially
170
- super.outputCommentToWriter(currentComment, writer, NODE_NOT_BEFORE_OR_AFTER_DOCUMENT_ELEMENT);
171
- }
132
+ return result.iterator();
133
+ }
134
+
135
+ /**
136
+ * Returns the Attr[]s to be output for the given element.
137
+ *
138
+ * @param element
139
+ * @param ns
140
+ * @return the Attr[]s to be output
141
+ * @throws CanonicalizationException
142
+ */
143
+ @Override
144
+ protected Iterator<Attr>
145
+ handleAttributes(Element element, NameSpaceSymbTable ns)
146
+ throws CanonicalizationException
147
+ {
148
+
149
+ /** $todo$ well, should we throw UnsupportedOperationException ? */
150
+ throw new CanonicalizationException("c14n.Canonicalizer.UnsupportedOperation");
151
+ }
152
+
153
+ @Override
154
+ protected void
155
+ handleParent(Element e, NameSpaceSymbTable ns)
156
+ {
157
+ // nothing to do
158
+ }
159
+
160
+ /** @inheritDoc */
161
+ @Override
162
+ public final String
163
+ engineGetURI()
164
+ {
165
+ return Canonicalizer.ALGO_ID_C14N_PHYSICAL;
166
+ }
167
+
168
+ /** @inheritDoc */
169
+ @Override
170
+ public final boolean
171
+ engineGetIncludeComments()
172
+ {
173
+ return true;
174
+ }
175
+
176
+ @Override
177
+ protected void
178
+ outputPItoWriter(ProcessingInstruction currentPI,
179
+ OutputStream writer, int position) throws IOException
180
+ {
181
+ // Processing Instructions before or after the document element are not treated specially
182
+ super.outputPItoWriter(currentPI, writer, NODE_NOT_BEFORE_OR_AFTER_DOCUMENT_ELEMENT);
183
+ }
184
+
185
+ @Override
186
+ protected void
187
+ outputCommentToWriter(Comment currentComment,
188
+ OutputStream writer, int position) throws IOException
189
+ {
190
+ // Comments before or after the document element are not treated specially
191
+ super.outputCommentToWriter(currentComment, writer, NODE_NOT_BEFORE_OR_AFTER_DOCUMENT_ELEMENT);
192
+ }
172
193
 
173
194
  }
@@ -28,49 +28,50 @@ import org.w3c.dom.Node;
28
28
  *
29
29
  * @author Christian Geuer-Pollmann
30
30
  */
31
- public abstract class CanonicalizerSpi {
31
+ public abstract class CanonicalizerSpi
32
+ {
32
33
 
33
- /** Reset the writer after a c14n */
34
- protected boolean reset = false;
34
+ /** Reset the writer after a c14n */
35
+ protected boolean reset = false;
35
36
 
36
- /**
37
- * Returns the URI of this engine.
38
- * @return the URI
39
- */
40
- public abstract String engineGetURI();
37
+ /**
38
+ * Returns the URI of this engine.
39
+ * @return the URI
40
+ */
41
+ public abstract String engineGetURI();
41
42
 
42
- /**
43
- * Returns true if comments are included
44
- * @return true if comments are included
45
- */
46
- public abstract boolean engineGetIncludeComments();
43
+ /**
44
+ * Returns true if comments are included
45
+ * @return true if comments are included
46
+ */
47
+ public abstract boolean engineGetIncludeComments();
47
48
 
48
- /**
49
- * C14n a node tree.
50
- *
51
- * @param rootNode
52
- * @return the c14n bytes
53
- * @throws CanonicalizationException
54
- */
55
- public abstract byte[] engineCanonicalizeSubTree(Node rootNode, CanonicalFilter filter)
56
- throws CanonicalizationException;
49
+ /**
50
+ * C14n a node tree.
51
+ *
52
+ * @param rootNode
53
+ * @return the c14n bytes
54
+ * @throws CanonicalizationException
55
+ */
56
+ public abstract byte[] engineCanonicalizeSubTree(Node rootNode, CanonicalFilter filter)
57
+ throws CanonicalizationException;
57
58
 
58
- /**
59
- * C14n a node tree.
60
- *
61
- * @param rootNode
62
- * @param inclusiveNamespaces
63
- * @return the c14n bytes
64
- * @throws CanonicalizationException
65
- */
66
- public abstract byte[] engineCanonicalizeSubTree(Node rootNode, String inclusiveNamespaces, CanonicalFilter filter)
67
- throws CanonicalizationException;
59
+ /**
60
+ * C14n a node tree.
61
+ *
62
+ * @param rootNode
63
+ * @param inclusiveNamespaces
64
+ * @return the c14n bytes
65
+ * @throws CanonicalizationException
66
+ */
67
+ public abstract byte[] engineCanonicalizeSubTree(Node rootNode, String inclusiveNamespaces, CanonicalFilter filter)
68
+ throws CanonicalizationException;
68
69
 
69
- /**
70
- * Sets the writer where the canonicalization ends. ByteArrayOutputStream if
71
- * none is set.
72
- * @param os
73
- */
74
- public abstract void setWriter(OutputStream os);
70
+ /**
71
+ * Sets the writer where the canonicalization ends. ByteArrayOutputStream if
72
+ * none is set.
73
+ * @param os
74
+ */
75
+ public abstract void setWriter(OutputStream os);
75
76
 
76
77
  }
@@ -27,16 +27,19 @@ package nokogiri.internals.c14n;
27
27
  *
28
28
  * @author $Author: coheigea $
29
29
  */
30
- public class Constants {
31
-
32
- /** The URI for XML spec*/
33
- public static final String XML_LANG_SPACE_SpecNS = "http://www.w3.org/XML/1998/namespace";
34
-
35
- /** The URI for XMLNS spec*/
36
- public static final String NamespaceSpecNS = "http://www.w3.org/2000/xmlns/";
30
+ public class Constants
31
+ {
37
32
 
38
- private Constants() {
39
- // we don't allow instantiation
40
- }
33
+ /** The URI for XML spec*/
34
+ public static final String XML_LANG_SPACE_SpecNS = "http://www.w3.org/XML/1998/namespace";
35
+
36
+ /** The URI for XMLNS spec*/
37
+ public static final String NamespaceSpecNS = "http://www.w3.org/2000/xmlns/";
38
+
39
+ private
40
+ Constants()
41
+ {
42
+ // we don't allow instantiation
43
+ }
41
44
 
42
45
  }
@@ -32,262 +32,294 @@ import org.w3c.dom.Text;
32
32
  * This is the base class to all Objects which have a direct 1:1 mapping to an
33
33
  * Element in a particular namespace.
34
34
  */
35
- public abstract class ElementProxy {
36
-
37
- /** Field constructionElement */
38
- protected Element constructionElement = null;
39
-
40
- /** Field baseURI */
41
- protected String baseURI = null;
42
-
43
- /** Field doc */
44
- protected Document doc = null;
45
-
46
- /** Field prefixMappings */
47
- private static Map<String, String> prefixMappings = new ConcurrentHashMap<String, String>();
48
-
49
- /**
50
- * Constructor ElementProxy
51
- *
52
- */
53
- public ElementProxy() {
35
+ public abstract class ElementProxy
36
+ {
37
+
38
+ /** Field constructionElement */
39
+ protected Element constructionElement = null;
40
+
41
+ /** Field baseURI */
42
+ protected String baseURI = null;
43
+
44
+ /** Field doc */
45
+ protected Document doc = null;
46
+
47
+ /** Field prefixMappings */
48
+ private static Map<String, String> prefixMappings = new ConcurrentHashMap<String, String>();
49
+
50
+ /**
51
+ * Constructor ElementProxy
52
+ *
53
+ */
54
+ public
55
+ ElementProxy()
56
+ {
57
+ }
58
+
59
+ /**
60
+ * Constructor ElementProxy
61
+ *
62
+ * @param doc
63
+ */
64
+ public
65
+ ElementProxy(Document doc)
66
+ {
67
+ if (doc == null) {
68
+ throw new RuntimeException("Document is null");
54
69
  }
55
70
 
56
- /**
57
- * Constructor ElementProxy
58
- *
59
- * @param doc
60
- */
61
- public ElementProxy(Document doc) {
62
- if (doc == null) {
63
- throw new RuntimeException("Document is null");
64
- }
65
-
66
- this.doc = doc;
67
- this.constructionElement =
68
- createElementForFamilyLocal(this.doc, this.getBaseNamespace(), this.getBaseLocalName());
71
+ this.doc = doc;
72
+ this.constructionElement =
73
+ createElementForFamilyLocal(this.doc, this.getBaseNamespace(), this.getBaseLocalName());
74
+ }
75
+
76
+ /**
77
+ * Constructor ElementProxy
78
+ *
79
+ * @param element
80
+ * @param BaseURI
81
+ * @throws XMLSecurityException
82
+ */
83
+ public
84
+ ElementProxy(Element element, String BaseURI) throws CanonicalizationException
85
+ {
86
+ if (element == null) {
87
+ throw new CanonicalizationException("ElementProxy.nullElement");
69
88
  }
70
-
71
- /**
72
- * Constructor ElementProxy
73
- *
74
- * @param element
75
- * @param BaseURI
76
- * @throws XMLSecurityException
77
- */
78
- public ElementProxy(Element element, String BaseURI) throws CanonicalizationException {
79
- if (element == null) {
80
- throw new CanonicalizationException("ElementProxy.nullElement");
81
- }
82
-
83
- //if (System.getProperty("nokogiri.c14.debug") == "on") {
84
- // System.out.println("setElement(\"" + element.getTagName() + "\", \"" + BaseURI + "\")");
85
- //}
86
-
87
- this.doc = element.getOwnerDocument();
88
- this.constructionElement = element;
89
- this.baseURI = BaseURI;
90
-
91
- this.guaranteeThatElementInCorrectSpace();
92
- }
93
-
94
- /**
95
- * Returns the namespace of the Elements of the sub-class.
96
- *
97
- * @return the namespace of the Elements of the sub-class.
98
- */
99
- public abstract String getBaseNamespace();
100
-
101
- /**
102
- * Returns the localname of the Elements of the sub-class.
103
- *
104
- * @return the localname of the Elements of the sub-class.
105
- */
106
- public abstract String getBaseLocalName();
107
-
108
-
109
- protected Element createElementForFamilyLocal(
110
- Document doc, String namespace, String localName
111
- ) {
112
- Element result;
113
- if (namespace == null) {
114
- result = doc.createElementNS(null, localName);
115
- } else {
116
- String baseName = this.getBaseNamespace();
117
- String prefix = ElementProxy.getDefaultPrefix(baseName);
118
- if ((prefix == null) || (prefix.length() == 0)) {
119
- result = doc.createElementNS(namespace, localName);
120
- result.setAttributeNS(Constants.NamespaceSpecNS, "xmlns", namespace);
121
- } else {
122
- result = doc.createElementNS(namespace, prefix + ":" + localName);
123
- result.setAttributeNS(Constants.NamespaceSpecNS, "xmlns:" + prefix, namespace);
124
- }
125
- }
126
- return result;
127
- }
128
-
129
89
 
130
- /**
131
- * This method creates an Element in a given namespace with a given localname.
132
- * It uses the {@link ElementProxy#getDefaultPrefix} method to decide whether
133
- * a particular prefix is bound to that namespace.
134
- * <BR />
135
- * This method was refactored out of the constructor.
136
- *
137
- * @param doc
138
- * @param namespace
139
- * @param localName
140
- * @return The element created.
141
- */
142
- public static Element createElementForFamily(Document doc, String namespace, String localName) {
143
- Element result;
144
- String prefix = ElementProxy.getDefaultPrefix(namespace);
145
-
146
- if (namespace == null) {
147
- result = doc.createElementNS(null, localName);
148
- } else {
149
- if ((prefix == null) || (prefix.length() == 0)) {
150
- result = doc.createElementNS(namespace, localName);
151
- result.setAttributeNS(Constants.NamespaceSpecNS, "xmlns", namespace);
152
- } else {
153
- result = doc.createElementNS(namespace, prefix + ":" + localName);
154
- result.setAttributeNS(Constants.NamespaceSpecNS, "xmlns:" + prefix, namespace);
155
- }
156
- }
157
-
158
- return result;
90
+ //if (System.getProperty("nokogiri.c14.debug") == "on") {
91
+ // System.out.println("setElement(\"" + element.getTagName() + "\", \"" + BaseURI + "\")");
92
+ //}
93
+
94
+ this.doc = element.getOwnerDocument();
95
+ this.constructionElement = element;
96
+ this.baseURI = BaseURI;
97
+
98
+ this.guaranteeThatElementInCorrectSpace();
99
+ }
100
+
101
+ /**
102
+ * Returns the namespace of the Elements of the sub-class.
103
+ *
104
+ * @return the namespace of the Elements of the sub-class.
105
+ */
106
+ public abstract String getBaseNamespace();
107
+
108
+ /**
109
+ * Returns the localname of the Elements of the sub-class.
110
+ *
111
+ * @return the localname of the Elements of the sub-class.
112
+ */
113
+ public abstract String getBaseLocalName();
114
+
115
+
116
+ protected Element
117
+ createElementForFamilyLocal(
118
+ Document doc, String namespace, String localName
119
+ )
120
+ {
121
+ Element result;
122
+ if (namespace == null) {
123
+ result = doc.createElementNS(null, localName);
124
+ } else {
125
+ String baseName = this.getBaseNamespace();
126
+ String prefix = ElementProxy.getDefaultPrefix(baseName);
127
+ if ((prefix == null) || (prefix.length() == 0)) {
128
+ result = doc.createElementNS(namespace, localName);
129
+ result.setAttributeNS(Constants.NamespaceSpecNS, "xmlns", namespace);
130
+ } else {
131
+ result = doc.createElementNS(namespace, prefix + ":" + localName);
132
+ result.setAttributeNS(Constants.NamespaceSpecNS, "xmlns:" + prefix, namespace);
133
+ }
159
134
  }
160
-
161
- /**
162
- * Returns the Element which was constructed by the Object.
163
- *
164
- * @return the Element which was constructed by the Object.
165
- */
166
- public final Element getElement() {
167
- return this.constructionElement;
135
+ return result;
136
+ }
137
+
138
+
139
+ /**
140
+ * This method creates an Element in a given namespace with a given localname.
141
+ * It uses the {@link ElementProxy#getDefaultPrefix} method to decide whether
142
+ * a particular prefix is bound to that namespace.
143
+ * <BR />
144
+ * This method was refactored out of the constructor.
145
+ *
146
+ * @param doc
147
+ * @param namespace
148
+ * @param localName
149
+ * @return The element created.
150
+ */
151
+ public static Element
152
+ createElementForFamily(Document doc, String namespace, String localName)
153
+ {
154
+ Element result;
155
+ String prefix = ElementProxy.getDefaultPrefix(namespace);
156
+
157
+ if (namespace == null) {
158
+ result = doc.createElementNS(null, localName);
159
+ } else {
160
+ if ((prefix == null) || (prefix.length() == 0)) {
161
+ result = doc.createElementNS(namespace, localName);
162
+ result.setAttributeNS(Constants.NamespaceSpecNS, "xmlns", namespace);
163
+ } else {
164
+ result = doc.createElementNS(namespace, prefix + ":" + localName);
165
+ result.setAttributeNS(Constants.NamespaceSpecNS, "xmlns:" + prefix, namespace);
166
+ }
168
167
  }
169
168
 
170
- /**
171
- * Returns the Element plus a leading and a trailing CarriageReturn Text node.
172
- *
173
- * @return the Element which was constructed by the Object.
174
- */
175
- public final NodeList getElementPlusReturns() {
176
-
177
- HelperNodeList nl = new HelperNodeList();
178
-
179
- nl.appendChild(this.doc.createTextNode("\n"));
180
- nl.appendChild(this.getElement());
181
- nl.appendChild(this.doc.createTextNode("\n"));
182
-
183
- return nl;
169
+ return result;
170
+ }
171
+
172
+ /**
173
+ * Returns the Element which was constructed by the Object.
174
+ *
175
+ * @return the Element which was constructed by the Object.
176
+ */
177
+ public final Element
178
+ getElement()
179
+ {
180
+ return this.constructionElement;
181
+ }
182
+
183
+ /**
184
+ * Returns the Element plus a leading and a trailing CarriageReturn Text node.
185
+ *
186
+ * @return the Element which was constructed by the Object.
187
+ */
188
+ public final NodeList
189
+ getElementPlusReturns()
190
+ {
191
+
192
+ HelperNodeList nl = new HelperNodeList();
193
+
194
+ nl.appendChild(this.doc.createTextNode("\n"));
195
+ nl.appendChild(this.getElement());
196
+ nl.appendChild(this.doc.createTextNode("\n"));
197
+
198
+ return nl;
199
+ }
200
+
201
+ /**
202
+ * Method getDocument
203
+ *
204
+ * @return the Document where this element is contained.
205
+ */
206
+ public Document
207
+ getDocument()
208
+ {
209
+ return this.doc;
210
+ }
211
+
212
+ /**
213
+ * Method getBaseURI
214
+ *
215
+ * @return the base uri of the namespace of this element
216
+ */
217
+ public String
218
+ getBaseURI()
219
+ {
220
+ return this.baseURI;
221
+ }
222
+
223
+ /**
224
+ * Method guaranteeThatElementInCorrectSpace
225
+ *
226
+ * @throws XMLSecurityException
227
+ */
228
+ void
229
+ guaranteeThatElementInCorrectSpace() throws CanonicalizationException
230
+ {
231
+
232
+ String expectedLocalName = this.getBaseLocalName();
233
+ String expectedNamespaceUri = this.getBaseNamespace();
234
+
235
+ String actualLocalName = this.constructionElement.getLocalName();
236
+ String actualNamespaceUri = this.constructionElement.getNamespaceURI();
237
+
238
+ if (!expectedNamespaceUri.equals(actualNamespaceUri)
239
+ && !expectedLocalName.equals(actualLocalName)) {
240
+ Object exArgs[] = { actualNamespaceUri + ":" + actualLocalName,
241
+ expectedNamespaceUri + ":" + expectedLocalName
242
+ };
243
+ throw new CanonicalizationException("xml.WrongElement", exArgs);
184
244
  }
185
-
186
- /**
187
- * Method getDocument
188
- *
189
- * @return the Document where this element is contained.
190
- */
191
- public Document getDocument() {
192
- return this.doc;
245
+ }
246
+
247
+ /**
248
+ * Method addText
249
+ *
250
+ * @param text
251
+ */
252
+ public void
253
+ addText(String text)
254
+ {
255
+ if (text != null) {
256
+ Text t = this.doc.createTextNode(text);
257
+
258
+ this.constructionElement.appendChild(t);
193
259
  }
194
-
195
- /**
196
- * Method getBaseURI
197
- *
198
- * @return the base uri of the namespace of this element
199
- */
200
- public String getBaseURI() {
201
- return this.baseURI;
202
- }
203
-
204
- /**
205
- * Method guaranteeThatElementInCorrectSpace
206
- *
207
- * @throws XMLSecurityException
208
- */
209
- void guaranteeThatElementInCorrectSpace() throws CanonicalizationException {
210
-
211
- String expectedLocalName = this.getBaseLocalName();
212
- String expectedNamespaceUri = this.getBaseNamespace();
213
-
214
- String actualLocalName = this.constructionElement.getLocalName();
215
- String actualNamespaceUri = this.constructionElement.getNamespaceURI();
216
-
217
- if(!expectedNamespaceUri.equals(actualNamespaceUri)
218
- && !expectedLocalName.equals(actualLocalName)) {
219
- Object exArgs[] = { actualNamespaceUri + ":" + actualLocalName,
220
- expectedNamespaceUri + ":" + expectedLocalName};
221
- throw new CanonicalizationException("xml.WrongElement", exArgs);
222
- }
223
- }
224
-
225
- /**
226
- * Method addText
227
- *
228
- * @param text
229
- */
230
- public void addText(String text) {
231
- if (text != null) {
232
- Text t = this.doc.createTextNode(text);
233
-
234
- this.constructionElement.appendChild(t);
235
- }
236
- }
237
-
238
- /**
239
- * Method getTextFromChildElement
240
- *
241
- * @param localname
242
- * @param namespace
243
- * @return the Text of the textNode
244
- */
245
- public String getTextFromChildElement(String localname, String namespace) {
246
- return XMLUtils.selectNode(
247
- this.constructionElement.getFirstChild(),
248
- namespace,
249
- localname,
250
- 0).getTextContent();
251
- }
252
-
253
- /**
254
- * Method getTextFromTextChild
255
- *
256
- * @return the Text obtained by concatenating all the text nodes of this
257
- * element
258
- */
259
- public String getTextFromTextChild() {
260
- return XMLUtils.getFullTextChildrenFromElement(this.constructionElement);
261
- }
262
-
263
- /**
264
- * Method length
265
- *
266
- * @param namespace
267
- * @param localname
268
- * @return the number of elements {namespace}:localname under this element
269
- */
270
- public int length(String namespace, String localname) {
271
- int number = 0;
272
- Node sibling = this.constructionElement.getFirstChild();
273
- while (sibling != null) {
274
- if (localname.equals(sibling.getLocalName())
275
- && namespace.equals(sibling.getNamespaceURI())) {
276
- number++;
277
- }
278
- sibling = sibling.getNextSibling();
279
- }
280
- return number;
281
- }
282
-
283
- /**
284
- * Method getDefaultPrefix
285
- *
286
- * @param namespace
287
- * @return the default prefix bind to this element.
288
- */
289
- public static String getDefaultPrefix(String namespace) {
290
- return prefixMappings.get(namespace);
260
+ }
261
+
262
+ /**
263
+ * Method getTextFromChildElement
264
+ *
265
+ * @param localname
266
+ * @param namespace
267
+ * @return the Text of the textNode
268
+ */
269
+ public String
270
+ getTextFromChildElement(String localname, String namespace)
271
+ {
272
+ return XMLUtils.selectNode(
273
+ this.constructionElement.getFirstChild(),
274
+ namespace,
275
+ localname,
276
+ 0).getTextContent();
277
+ }
278
+
279
+ /**
280
+ * Method getTextFromTextChild
281
+ *
282
+ * @return the Text obtained by concatenating all the text nodes of this
283
+ * element
284
+ */
285
+ public String
286
+ getTextFromTextChild()
287
+ {
288
+ return XMLUtils.getFullTextChildrenFromElement(this.constructionElement);
289
+ }
290
+
291
+ /**
292
+ * Method length
293
+ *
294
+ * @param namespace
295
+ * @param localname
296
+ * @return the number of elements {namespace}:localname under this element
297
+ */
298
+ public int
299
+ length(String namespace, String localname)
300
+ {
301
+ int number = 0;
302
+ Node sibling = this.constructionElement.getFirstChild();
303
+ while (sibling != null) {
304
+ if (localname.equals(sibling.getLocalName())
305
+ && namespace.equals(sibling.getNamespaceURI())) {
306
+ number++;
307
+ }
308
+ sibling = sibling.getNextSibling();
291
309
  }
310
+ return number;
311
+ }
312
+
313
+ /**
314
+ * Method getDefaultPrefix
315
+ *
316
+ * @param namespace
317
+ * @return the default prefix bind to this element.
318
+ */
319
+ public static String
320
+ getDefaultPrefix(String namespace)
321
+ {
322
+ return prefixMappings.get(namespace);
323
+ }
292
324
 
293
325
  }