nokogiri-backport 1.11.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (239) hide show
  1. checksums.yaml +7 -0
  2. data/Gemfile +3 -0
  3. data/LICENSE-DEPENDENCIES.md +1682 -0
  4. data/LICENSE.md +9 -0
  5. data/README.md +272 -0
  6. data/bin/nokogiri +118 -0
  7. data/dependencies.yml +74 -0
  8. data/ext/java/nokogiri/EncodingHandler.java +124 -0
  9. data/ext/java/nokogiri/HtmlDocument.java +178 -0
  10. data/ext/java/nokogiri/HtmlElementDescription.java +148 -0
  11. data/ext/java/nokogiri/HtmlEntityLookup.java +79 -0
  12. data/ext/java/nokogiri/HtmlSaxParserContext.java +282 -0
  13. data/ext/java/nokogiri/HtmlSaxPushParser.java +222 -0
  14. data/ext/java/nokogiri/NokogiriService.java +597 -0
  15. data/ext/java/nokogiri/XmlAttr.java +162 -0
  16. data/ext/java/nokogiri/XmlAttributeDecl.java +129 -0
  17. data/ext/java/nokogiri/XmlCdata.java +82 -0
  18. data/ext/java/nokogiri/XmlComment.java +97 -0
  19. data/ext/java/nokogiri/XmlDocument.java +633 -0
  20. data/ext/java/nokogiri/XmlDocumentFragment.java +185 -0
  21. data/ext/java/nokogiri/XmlDtd.java +481 -0
  22. data/ext/java/nokogiri/XmlElement.java +68 -0
  23. data/ext/java/nokogiri/XmlElementContent.java +382 -0
  24. data/ext/java/nokogiri/XmlElementDecl.java +147 -0
  25. data/ext/java/nokogiri/XmlEntityDecl.java +157 -0
  26. data/ext/java/nokogiri/XmlEntityReference.java +101 -0
  27. data/ext/java/nokogiri/XmlNamespace.java +199 -0
  28. data/ext/java/nokogiri/XmlNode.java +1684 -0
  29. data/ext/java/nokogiri/XmlNodeSet.java +434 -0
  30. data/ext/java/nokogiri/XmlProcessingInstruction.java +100 -0
  31. data/ext/java/nokogiri/XmlReader.java +531 -0
  32. data/ext/java/nokogiri/XmlRelaxng.java +151 -0
  33. data/ext/java/nokogiri/XmlSaxParserContext.java +374 -0
  34. data/ext/java/nokogiri/XmlSaxPushParser.java +286 -0
  35. data/ext/java/nokogiri/XmlSchema.java +388 -0
  36. data/ext/java/nokogiri/XmlSyntaxError.java +138 -0
  37. data/ext/java/nokogiri/XmlText.java +110 -0
  38. data/ext/java/nokogiri/XmlXpathContext.java +301 -0
  39. data/ext/java/nokogiri/XsltStylesheet.java +347 -0
  40. data/ext/java/nokogiri/internals/ClosedStreamException.java +10 -0
  41. data/ext/java/nokogiri/internals/HtmlDomParserContext.java +252 -0
  42. data/ext/java/nokogiri/internals/IgnoreSchemaErrorsErrorHandler.java +20 -0
  43. data/ext/java/nokogiri/internals/NokogiriBlockingQueueInputStream.java +151 -0
  44. data/ext/java/nokogiri/internals/NokogiriDomParser.java +116 -0
  45. data/ext/java/nokogiri/internals/NokogiriEntityResolver.java +121 -0
  46. data/ext/java/nokogiri/internals/NokogiriErrorHandler.java +69 -0
  47. data/ext/java/nokogiri/internals/NokogiriHandler.java +327 -0
  48. data/ext/java/nokogiri/internals/NokogiriHelpers.java +734 -0
  49. data/ext/java/nokogiri/internals/NokogiriNamespaceCache.java +217 -0
  50. data/ext/java/nokogiri/internals/NokogiriNamespaceContext.java +127 -0
  51. data/ext/java/nokogiri/internals/NokogiriNonStrictErrorHandler.java +100 -0
  52. data/ext/java/nokogiri/internals/NokogiriNonStrictErrorHandler4NekoHtml.java +121 -0
  53. data/ext/java/nokogiri/internals/NokogiriStrictErrorHandler.java +78 -0
  54. data/ext/java/nokogiri/internals/NokogiriXPathFunction.java +180 -0
  55. data/ext/java/nokogiri/internals/NokogiriXPathFunctionResolver.java +72 -0
  56. data/ext/java/nokogiri/internals/NokogiriXPathVariableResolver.java +60 -0
  57. data/ext/java/nokogiri/internals/NokogiriXsltErrorListener.java +87 -0
  58. data/ext/java/nokogiri/internals/ParserContext.java +259 -0
  59. data/ext/java/nokogiri/internals/ReaderNode.java +488 -0
  60. data/ext/java/nokogiri/internals/SaveContextVisitor.java +778 -0
  61. data/ext/java/nokogiri/internals/SchemaErrorHandler.java +73 -0
  62. data/ext/java/nokogiri/internals/XalanDTMManagerPatch.java +168 -0
  63. data/ext/java/nokogiri/internals/XmlDeclHandler.java +42 -0
  64. data/ext/java/nokogiri/internals/XmlDomParserContext.java +274 -0
  65. data/ext/java/nokogiri/internals/XmlSaxParser.java +65 -0
  66. data/ext/java/nokogiri/internals/c14n/AttrCompare.java +119 -0
  67. data/ext/java/nokogiri/internals/c14n/C14nHelper.java +159 -0
  68. data/ext/java/nokogiri/internals/c14n/CanonicalFilter.java +37 -0
  69. data/ext/java/nokogiri/internals/c14n/CanonicalizationException.java +93 -0
  70. data/ext/java/nokogiri/internals/c14n/Canonicalizer.java +252 -0
  71. data/ext/java/nokogiri/internals/c14n/Canonicalizer11.java +639 -0
  72. data/ext/java/nokogiri/internals/c14n/Canonicalizer11_OmitComments.java +38 -0
  73. data/ext/java/nokogiri/internals/c14n/Canonicalizer11_WithComments.java +38 -0
  74. data/ext/java/nokogiri/internals/c14n/Canonicalizer20010315.java +367 -0
  75. data/ext/java/nokogiri/internals/c14n/Canonicalizer20010315Excl.java +295 -0
  76. data/ext/java/nokogiri/internals/c14n/Canonicalizer20010315ExclOmitComments.java +40 -0
  77. data/ext/java/nokogiri/internals/c14n/Canonicalizer20010315ExclWithComments.java +44 -0
  78. data/ext/java/nokogiri/internals/c14n/Canonicalizer20010315OmitComments.java +44 -0
  79. data/ext/java/nokogiri/internals/c14n/Canonicalizer20010315WithComments.java +43 -0
  80. data/ext/java/nokogiri/internals/c14n/CanonicalizerBase.java +630 -0
  81. data/ext/java/nokogiri/internals/c14n/CanonicalizerPhysical.java +173 -0
  82. data/ext/java/nokogiri/internals/c14n/CanonicalizerSpi.java +76 -0
  83. data/ext/java/nokogiri/internals/c14n/Constants.java +42 -0
  84. data/ext/java/nokogiri/internals/c14n/ElementProxy.java +293 -0
  85. data/ext/java/nokogiri/internals/c14n/HelperNodeList.java +93 -0
  86. data/ext/java/nokogiri/internals/c14n/IgnoreAllErrorHandler.java +79 -0
  87. data/ext/java/nokogiri/internals/c14n/InclusiveNamespaces.java +166 -0
  88. data/ext/java/nokogiri/internals/c14n/InvalidCanonicalizerException.java +76 -0
  89. data/ext/java/nokogiri/internals/c14n/NameSpaceSymbTable.java +402 -0
  90. data/ext/java/nokogiri/internals/c14n/NodeFilter.java +51 -0
  91. data/ext/java/nokogiri/internals/c14n/UtfHelpper.java +179 -0
  92. data/ext/java/nokogiri/internals/c14n/XMLUtils.java +507 -0
  93. data/ext/java/nokogiri/internals/dom2dtm/DOM2DTM.java +1745 -0
  94. data/ext/java/nokogiri/internals/dom2dtm/DOM2DTMdefaultNamespaceDeclarationNode.java +685 -0
  95. data/ext/nokogiri/depend +477 -0
  96. data/ext/nokogiri/extconf.rb +836 -0
  97. data/ext/nokogiri/html_document.c +171 -0
  98. data/ext/nokogiri/html_document.h +10 -0
  99. data/ext/nokogiri/html_element_description.c +279 -0
  100. data/ext/nokogiri/html_element_description.h +10 -0
  101. data/ext/nokogiri/html_entity_lookup.c +32 -0
  102. data/ext/nokogiri/html_entity_lookup.h +8 -0
  103. data/ext/nokogiri/html_sax_parser_context.c +116 -0
  104. data/ext/nokogiri/html_sax_parser_context.h +11 -0
  105. data/ext/nokogiri/html_sax_push_parser.c +87 -0
  106. data/ext/nokogiri/html_sax_push_parser.h +9 -0
  107. data/ext/nokogiri/nokogiri.c +135 -0
  108. data/ext/nokogiri/nokogiri.h +130 -0
  109. data/ext/nokogiri/xml_attr.c +103 -0
  110. data/ext/nokogiri/xml_attr.h +9 -0
  111. data/ext/nokogiri/xml_attribute_decl.c +70 -0
  112. data/ext/nokogiri/xml_attribute_decl.h +9 -0
  113. data/ext/nokogiri/xml_cdata.c +62 -0
  114. data/ext/nokogiri/xml_cdata.h +9 -0
  115. data/ext/nokogiri/xml_comment.c +69 -0
  116. data/ext/nokogiri/xml_comment.h +9 -0
  117. data/ext/nokogiri/xml_document.c +622 -0
  118. data/ext/nokogiri/xml_document.h +23 -0
  119. data/ext/nokogiri/xml_document_fragment.c +48 -0
  120. data/ext/nokogiri/xml_document_fragment.h +10 -0
  121. data/ext/nokogiri/xml_dtd.c +202 -0
  122. data/ext/nokogiri/xml_dtd.h +10 -0
  123. data/ext/nokogiri/xml_element_content.c +123 -0
  124. data/ext/nokogiri/xml_element_content.h +10 -0
  125. data/ext/nokogiri/xml_element_decl.c +69 -0
  126. data/ext/nokogiri/xml_element_decl.h +9 -0
  127. data/ext/nokogiri/xml_encoding_handler.c +79 -0
  128. data/ext/nokogiri/xml_encoding_handler.h +8 -0
  129. data/ext/nokogiri/xml_entity_decl.c +110 -0
  130. data/ext/nokogiri/xml_entity_decl.h +10 -0
  131. data/ext/nokogiri/xml_entity_reference.c +52 -0
  132. data/ext/nokogiri/xml_entity_reference.h +9 -0
  133. data/ext/nokogiri/xml_io.c +63 -0
  134. data/ext/nokogiri/xml_io.h +11 -0
  135. data/ext/nokogiri/xml_libxml2_hacks.c +112 -0
  136. data/ext/nokogiri/xml_libxml2_hacks.h +12 -0
  137. data/ext/nokogiri/xml_namespace.c +111 -0
  138. data/ext/nokogiri/xml_namespace.h +14 -0
  139. data/ext/nokogiri/xml_node.c +1773 -0
  140. data/ext/nokogiri/xml_node.h +13 -0
  141. data/ext/nokogiri/xml_node_set.c +486 -0
  142. data/ext/nokogiri/xml_node_set.h +12 -0
  143. data/ext/nokogiri/xml_processing_instruction.c +56 -0
  144. data/ext/nokogiri/xml_processing_instruction.h +9 -0
  145. data/ext/nokogiri/xml_reader.c +657 -0
  146. data/ext/nokogiri/xml_reader.h +10 -0
  147. data/ext/nokogiri/xml_relax_ng.c +179 -0
  148. data/ext/nokogiri/xml_relax_ng.h +9 -0
  149. data/ext/nokogiri/xml_sax_parser.c +305 -0
  150. data/ext/nokogiri/xml_sax_parser.h +39 -0
  151. data/ext/nokogiri/xml_sax_parser_context.c +262 -0
  152. data/ext/nokogiri/xml_sax_parser_context.h +10 -0
  153. data/ext/nokogiri/xml_sax_push_parser.c +159 -0
  154. data/ext/nokogiri/xml_sax_push_parser.h +9 -0
  155. data/ext/nokogiri/xml_schema.c +276 -0
  156. data/ext/nokogiri/xml_schema.h +9 -0
  157. data/ext/nokogiri/xml_syntax_error.c +64 -0
  158. data/ext/nokogiri/xml_syntax_error.h +13 -0
  159. data/ext/nokogiri/xml_text.c +52 -0
  160. data/ext/nokogiri/xml_text.h +9 -0
  161. data/ext/nokogiri/xml_xpath_context.c +374 -0
  162. data/ext/nokogiri/xml_xpath_context.h +10 -0
  163. data/ext/nokogiri/xslt_stylesheet.c +263 -0
  164. data/ext/nokogiri/xslt_stylesheet.h +14 -0
  165. data/lib/isorelax.jar +0 -0
  166. data/lib/jing.jar +0 -0
  167. data/lib/nekodtd.jar +0 -0
  168. data/lib/nekohtml.jar +0 -0
  169. data/lib/nokogiri/css/node.rb +53 -0
  170. data/lib/nokogiri/css/parser.rb +751 -0
  171. data/lib/nokogiri/css/parser.y +272 -0
  172. data/lib/nokogiri/css/parser_extras.rb +94 -0
  173. data/lib/nokogiri/css/syntax_error.rb +8 -0
  174. data/lib/nokogiri/css/tokenizer.rb +154 -0
  175. data/lib/nokogiri/css/tokenizer.rex +55 -0
  176. data/lib/nokogiri/css/xpath_visitor.rb +260 -0
  177. data/lib/nokogiri/css.rb +28 -0
  178. data/lib/nokogiri/decorators/slop.rb +43 -0
  179. data/lib/nokogiri/html/builder.rb +36 -0
  180. data/lib/nokogiri/html/document.rb +322 -0
  181. data/lib/nokogiri/html/document_fragment.rb +50 -0
  182. data/lib/nokogiri/html/element_description.rb +24 -0
  183. data/lib/nokogiri/html/element_description_defaults.rb +672 -0
  184. data/lib/nokogiri/html/entity_lookup.rb +14 -0
  185. data/lib/nokogiri/html/sax/parser.rb +63 -0
  186. data/lib/nokogiri/html/sax/parser_context.rb +17 -0
  187. data/lib/nokogiri/html/sax/push_parser.rb +37 -0
  188. data/lib/nokogiri/html.rb +38 -0
  189. data/lib/nokogiri/jruby/dependencies.rb +20 -0
  190. data/lib/nokogiri/syntax_error.rb +5 -0
  191. data/lib/nokogiri/version/constant.rb +5 -0
  192. data/lib/nokogiri/version/info.rb +182 -0
  193. data/lib/nokogiri/version.rb +3 -0
  194. data/lib/nokogiri/xml/attr.rb +15 -0
  195. data/lib/nokogiri/xml/attribute_decl.rb +19 -0
  196. data/lib/nokogiri/xml/builder.rb +447 -0
  197. data/lib/nokogiri/xml/cdata.rb +12 -0
  198. data/lib/nokogiri/xml/character_data.rb +8 -0
  199. data/lib/nokogiri/xml/document.rb +290 -0
  200. data/lib/nokogiri/xml/document_fragment.rb +159 -0
  201. data/lib/nokogiri/xml/dtd.rb +33 -0
  202. data/lib/nokogiri/xml/element_content.rb +37 -0
  203. data/lib/nokogiri/xml/element_decl.rb +14 -0
  204. data/lib/nokogiri/xml/entity_decl.rb +20 -0
  205. data/lib/nokogiri/xml/entity_reference.rb +19 -0
  206. data/lib/nokogiri/xml/namespace.rb +14 -0
  207. data/lib/nokogiri/xml/node/save_options.rb +62 -0
  208. data/lib/nokogiri/xml/node.rb +1240 -0
  209. data/lib/nokogiri/xml/node_set.rb +372 -0
  210. data/lib/nokogiri/xml/notation.rb +7 -0
  211. data/lib/nokogiri/xml/parse_options.rb +127 -0
  212. data/lib/nokogiri/xml/pp/character_data.rb +19 -0
  213. data/lib/nokogiri/xml/pp/node.rb +57 -0
  214. data/lib/nokogiri/xml/pp.rb +3 -0
  215. data/lib/nokogiri/xml/processing_instruction.rb +9 -0
  216. data/lib/nokogiri/xml/reader.rb +116 -0
  217. data/lib/nokogiri/xml/relax_ng.rb +37 -0
  218. data/lib/nokogiri/xml/sax/document.rb +172 -0
  219. data/lib/nokogiri/xml/sax/parser.rb +123 -0
  220. data/lib/nokogiri/xml/sax/parser_context.rb +17 -0
  221. data/lib/nokogiri/xml/sax/push_parser.rb +61 -0
  222. data/lib/nokogiri/xml/sax.rb +5 -0
  223. data/lib/nokogiri/xml/schema.rb +72 -0
  224. data/lib/nokogiri/xml/searchable.rb +239 -0
  225. data/lib/nokogiri/xml/syntax_error.rb +71 -0
  226. data/lib/nokogiri/xml/text.rb +10 -0
  227. data/lib/nokogiri/xml/xpath/syntax_error.rb +12 -0
  228. data/lib/nokogiri/xml/xpath.rb +11 -0
  229. data/lib/nokogiri/xml/xpath_context.rb +17 -0
  230. data/lib/nokogiri/xml.rb +76 -0
  231. data/lib/nokogiri/xslt/stylesheet.rb +26 -0
  232. data/lib/nokogiri/xslt.rb +57 -0
  233. data/lib/nokogiri.rb +144 -0
  234. data/lib/serializer.jar +0 -0
  235. data/lib/xalan.jar +0 -0
  236. data/lib/xercesImpl.jar +0 -0
  237. data/lib/xml-apis.jar +0 -0
  238. data/lib/xsd/xmlparser/nokogiri.rb +103 -0
  239. metadata +531 -0
@@ -0,0 +1,639 @@
1
+ /**
2
+ * Licensed to the Apache Software Foundation (ASF) under one
3
+ * or more contributor license agreements. See the NOTICE file
4
+ * distributed with this work for additional information
5
+ * regarding copyright ownership. The ASF licenses this file
6
+ * to you under the Apache License, Version 2.0 (the
7
+ * "License"); you may not use this file except in compliance
8
+ * with the License. You may obtain a copy of the License at
9
+ *
10
+ * http://www.apache.org/licenses/LICENSE-2.0
11
+ *
12
+ * Unless required by applicable law or agreed to in writing,
13
+ * software distributed under the License is distributed on an
14
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15
+ * KIND, either express or implied. See the License for the
16
+ * specific language governing permissions and limitations
17
+ * under the License.
18
+ */
19
+ package nokogiri.internals.c14n;
20
+
21
+ import java.net.URI;
22
+ import java.net.URISyntaxException;
23
+ import java.util.ArrayList;
24
+ import java.util.Collection;
25
+ import java.util.HashMap;
26
+ import java.util.Iterator;
27
+ import java.util.List;
28
+ import java.util.Map;
29
+ import java.util.SortedSet;
30
+ import java.util.TreeSet;
31
+
32
+
33
+ import org.w3c.dom.Attr;
34
+ import org.w3c.dom.Element;
35
+ import org.w3c.dom.NamedNodeMap;
36
+ import org.w3c.dom.Node;
37
+
38
+ /**
39
+ * Implements <A HREF="http://www.w3.org/TR/2008/PR-xml-c14n11-20080129/">
40
+ * Canonical XML Version 1.1</A>, a W3C Proposed Recommendation from 29
41
+ * January 2008.
42
+ *
43
+ * @author Sean Mullan
44
+ * @author Raul Benito
45
+ */
46
+ public abstract class Canonicalizer11 extends CanonicalizerBase {
47
+
48
+ private static final String XMLNS_URI = Constants.NamespaceSpecNS;
49
+ private static final String XML_LANG_URI = Constants.XML_LANG_SPACE_SpecNS;
50
+ private final SortedSet<Attr> result = new TreeSet<Attr>(COMPARE);
51
+
52
+ private boolean firstCall = true;
53
+
54
+ private static class XmlAttrStack {
55
+ static class XmlsStackElement {
56
+ int level;
57
+ boolean rendered = false;
58
+ List<Attr> nodes = new ArrayList<Attr>();
59
+ }
60
+
61
+ int currentLevel = 0;
62
+ int lastlevel = 0;
63
+ XmlsStackElement cur;
64
+ List<XmlsStackElement> levels = new ArrayList<XmlsStackElement>();
65
+
66
+ void push(int level) {
67
+ currentLevel = level;
68
+ if (currentLevel == -1) {
69
+ return;
70
+ }
71
+ cur = null;
72
+ while (lastlevel >= currentLevel) {
73
+ levels.remove(levels.size() - 1);
74
+ int newSize = levels.size();
75
+ if (newSize == 0) {
76
+ lastlevel = 0;
77
+ return;
78
+ }
79
+ lastlevel = (levels.get(newSize - 1)).level;
80
+ }
81
+ }
82
+
83
+ void addXmlnsAttr(Attr n) {
84
+ if (cur == null) {
85
+ cur = new XmlsStackElement();
86
+ cur.level = currentLevel;
87
+ levels.add(cur);
88
+ lastlevel = currentLevel;
89
+ }
90
+ cur.nodes.add(n);
91
+ }
92
+
93
+ void getXmlnsAttr(Collection<Attr> col) throws CanonicalizationException {
94
+ int size = levels.size() - 1;
95
+ if (cur == null) {
96
+ cur = new XmlsStackElement();
97
+ cur.level = currentLevel;
98
+ lastlevel = currentLevel;
99
+ levels.add(cur);
100
+ }
101
+ boolean parentRendered = false;
102
+ if (size == -1) {
103
+ parentRendered = true;
104
+ } else {
105
+ XmlsStackElement e = levels.get(size);
106
+ if (e.rendered && e.level + 1 == currentLevel) {
107
+ parentRendered = true;
108
+ }
109
+ }
110
+ if (parentRendered) {
111
+ col.addAll(cur.nodes);
112
+ cur.rendered = true;
113
+ return;
114
+ }
115
+
116
+ Map<String, Attr> loa = new HashMap<String, Attr>();
117
+ List<Attr> baseAttrs = new ArrayList<Attr>();
118
+ boolean successiveOmitted = true;
119
+ for (; size >= 0; size--) {
120
+ XmlsStackElement e = levels.get(size);
121
+ if (e.rendered) {
122
+ successiveOmitted = false;
123
+ }
124
+ Iterator<Attr> it = e.nodes.iterator();
125
+ while (it.hasNext() && successiveOmitted) {
126
+ Attr n = it.next();
127
+ if (n.getLocalName().equals("base") && !e.rendered) {
128
+ baseAttrs.add(n);
129
+ } else if (!loa.containsKey(n.getName())) {
130
+ loa.put(n.getName(), n);
131
+ }
132
+ }
133
+ }
134
+ if (!baseAttrs.isEmpty()) {
135
+ Iterator<Attr> it = col.iterator();
136
+ String base = null;
137
+ Attr baseAttr = null;
138
+ while (it.hasNext()) {
139
+ Attr n = it.next();
140
+ if (n.getLocalName().equals("base")) {
141
+ base = n.getValue();
142
+ baseAttr = n;
143
+ break;
144
+ }
145
+ }
146
+ it = baseAttrs.iterator();
147
+ while (it.hasNext()) {
148
+ Attr n = it.next();
149
+ if (base == null) {
150
+ base = n.getValue();
151
+ baseAttr = n;
152
+ } else {
153
+ try {
154
+ base = joinURI(n.getValue(), base);
155
+ } catch (URISyntaxException e1) {
156
+ throw new CanonicalizationException(e1);
157
+ }
158
+ }
159
+ }
160
+ if (base != null && base.length() != 0) {
161
+ baseAttr.setValue(base);
162
+ col.add(baseAttr);
163
+ }
164
+ }
165
+
166
+ cur.rendered = true;
167
+ col.addAll(loa.values());
168
+ }
169
+ }
170
+
171
+ private final XmlAttrStack xmlattrStack = new XmlAttrStack();
172
+
173
+ /**
174
+ * Constructor Canonicalizer11
175
+ *
176
+ * @param includeComments
177
+ */
178
+ public Canonicalizer11(boolean includeComments) {
179
+ super(includeComments);
180
+ }
181
+
182
+ /**
183
+ * Always throws a CanonicalizationException because this is inclusive c14n.
184
+ *
185
+ * @param rootNode
186
+ * @param inclusiveNamespaces
187
+ * @return none it always fails
188
+ * @throws CanonicalizationException
189
+ */
190
+ public byte[] engineCanonicalizeSubTree(
191
+ Node rootNode, String inclusiveNamespaces, CanonicalFilter filter
192
+ ) throws CanonicalizationException {
193
+ throw new CanonicalizationException("c14n.Canonicalizer.UnsupportedOperation");
194
+ }
195
+
196
+ /**
197
+ * Returns the Attr[]s to be output for the given element.
198
+ * <br>
199
+ * The code of this method is a copy of {@link #handleAttributes(Element,
200
+ * NameSpaceSymbTable)},
201
+ * whereas it takes into account that subtree-c14n is -- well --
202
+ * subtree-based.
203
+ * So if the element in question isRoot of c14n, it's parent is not in the
204
+ * node set, as well as all other ancestors.
205
+ *
206
+ * @param element
207
+ * @param ns
208
+ * @return the Attr[]s to be output
209
+ * @throws CanonicalizationException
210
+ * @throws URISyntaxException
211
+ */
212
+ @Override
213
+ protected Iterator<Attr> handleAttributesSubtree(Element element, NameSpaceSymbTable ns)
214
+ throws CanonicalizationException {
215
+ if (!element.hasAttributes() && !firstCall) {
216
+ return null;
217
+ }
218
+ // result will contain the attrs which have to be output
219
+ final SortedSet<Attr> result = this.result;
220
+ result.clear();
221
+
222
+ if (element.hasAttributes()) {
223
+ NamedNodeMap attrs = element.getAttributes();
224
+ int attrsLength = attrs.getLength();
225
+
226
+ for (int i = 0; i < attrsLength; i++) {
227
+ Attr attribute = (Attr) attrs.item(i);
228
+ String NUri = attribute.getNamespaceURI();
229
+ String NName = attribute.getLocalName();
230
+ String NValue = attribute.getValue();
231
+
232
+ if (!XMLNS_URI.equals(NUri)) {
233
+ // It's not a namespace attr node. Add to the result and continue.
234
+ result.add(attribute);
235
+ } else if (!(XML.equals(NName) && XML_LANG_URI.equals(NValue))) {
236
+ // The default mapping for xml must not be output.
237
+ Node n = ns.addMappingAndRender(NName, NValue, attribute);
238
+
239
+ if (n != null) {
240
+ // Render the ns definition
241
+ result.add((Attr)n);
242
+ if (C14nHelper.namespaceIsRelative(attribute)) {
243
+ Object exArgs[] = {element.getTagName(), NName, attribute.getNodeValue()};
244
+ throw new CanonicalizationException(
245
+ "c14n.Canonicalizer.RelativeNamespace", exArgs
246
+ );
247
+ }
248
+ }
249
+ }
250
+ }
251
+ }
252
+
253
+ if (firstCall) {
254
+ // It is the first node of the subtree
255
+ // Obtain all the namespaces defined in the parents, and added to the output.
256
+ ns.getUnrenderedNodes(result);
257
+ // output the attributes in the xml namespace.
258
+ xmlattrStack.getXmlnsAttr(result);
259
+ firstCall = false;
260
+ }
261
+
262
+ return result.iterator();
263
+ }
264
+
265
+ /**
266
+ * Returns the Attr[]s to be output for the given element.
267
+ * <br>
268
+ * IMPORTANT: This method expects to work on a modified DOM tree, i.e. a
269
+ * DOM which has been prepared using
270
+ * {@link nokogiri.internals.c14n.security.utils.XMLUtils#circumventBug2650(
271
+ * org.w3c.dom.Document)}.
272
+ *
273
+ * @param element
274
+ * @param ns
275
+ * @return the Attr[]s to be output
276
+ * @throws CanonicalizationException
277
+ */
278
+ @Override
279
+ protected Iterator<Attr> handleAttributes(Element element, NameSpaceSymbTable ns)
280
+ throws CanonicalizationException {
281
+ // result will contain the attrs which have to be output
282
+ xmlattrStack.push(ns.getLevel());
283
+ boolean isRealVisible = isVisibleDO(element, ns.getLevel()) == 1;
284
+ final SortedSet<Attr> result = this.result;
285
+ result.clear();
286
+
287
+ if (element.hasAttributes()) {
288
+ NamedNodeMap attrs = element.getAttributes();
289
+ int attrsLength = attrs.getLength();
290
+
291
+ for (int i = 0; i < attrsLength; i++) {
292
+ Attr attribute = (Attr) attrs.item(i);
293
+ String NUri = attribute.getNamespaceURI();
294
+ String NName = attribute.getLocalName();
295
+ String NValue = attribute.getValue();
296
+
297
+ if (!XMLNS_URI.equals(NUri)) {
298
+ //A non namespace definition node.
299
+ if (XML_LANG_URI.equals(NUri)) {
300
+ if (NName.equals("id")) {
301
+ if (isRealVisible) {
302
+ // treat xml:id like any other attribute
303
+ // (emit it, but don't inherit it)
304
+ result.add(attribute);
305
+ }
306
+ } else {
307
+ xmlattrStack.addXmlnsAttr(attribute);
308
+ }
309
+ } else if (isRealVisible) {
310
+ //The node is visible add the attribute to the list of output attributes.
311
+ result.add(attribute);
312
+ }
313
+ } else if (!XML.equals(NName) || !XML_LANG_URI.equals(NValue)) {
314
+ /* except omit namespace node with local name xml, which defines
315
+ * the xml prefix, if its string value is
316
+ * http://www.w3.org/XML/1998/namespace.
317
+ */
318
+ // add the prefix binding to the ns symb table.
319
+ if (isVisible(attribute)) {
320
+ if (isRealVisible || !ns.removeMappingIfRender(NName)) {
321
+ // The xpath select this node output it if needed.
322
+ Node n = ns.addMappingAndRender(NName, NValue, attribute);
323
+ if (n != null) {
324
+ result.add((Attr)n);
325
+ if (C14nHelper.namespaceIsRelative(attribute)) {
326
+ Object exArgs[] = { element.getTagName(), NName, attribute.getNodeValue() };
327
+ throw new CanonicalizationException(
328
+ "c14n.Canonicalizer.RelativeNamespace", exArgs
329
+ );
330
+ }
331
+ }
332
+ }
333
+ } else {
334
+ if (isRealVisible && !XMLNS.equals(NName)) {
335
+ ns.removeMapping(NName);
336
+ } else {
337
+ ns.addMapping(NName, NValue, attribute);
338
+ }
339
+ }
340
+ }
341
+ }
342
+ }
343
+
344
+ if (isRealVisible) {
345
+ //The element is visible, handle the xmlns definition
346
+ Attr xmlns = element.getAttributeNodeNS(XMLNS_URI, XMLNS);
347
+ Node n = null;
348
+ if (xmlns == null) {
349
+ //No xmlns def just get the already defined.
350
+ n = ns.getMapping(XMLNS);
351
+ } else if (!isVisible(xmlns)) {
352
+ //There is a definition but the xmlns is not selected by the xpath.
353
+ //then xmlns=""
354
+ n = ns.addMappingAndRender(XMLNS, "", nullNode);
355
+ }
356
+ //output the xmlns def if needed.
357
+ if (n != null) {
358
+ result.add((Attr)n);
359
+ }
360
+ //Float all xml:* attributes of the unselected parent elements to this one.
361
+ xmlattrStack.getXmlnsAttr(result);
362
+ ns.getUnrenderedNodes(result);
363
+ }
364
+
365
+ return result.iterator();
366
+ }
367
+
368
+ @Override
369
+ protected void handleParent(Element e, NameSpaceSymbTable ns) {
370
+ if (!e.hasAttributes() && e.getNamespaceURI() == null) {
371
+ return;
372
+ }
373
+ xmlattrStack.push(-1);
374
+ NamedNodeMap attrs = e.getAttributes();
375
+ int attrsLength = attrs.getLength();
376
+ for (int i = 0; i < attrsLength; i++) {
377
+ Attr attribute = (Attr) attrs.item(i);
378
+ String NName = attribute.getLocalName();
379
+ String NValue = attribute.getNodeValue();
380
+
381
+ if (Constants.NamespaceSpecNS.equals(attribute.getNamespaceURI())) {
382
+ if (!XML.equals(NName) || !Constants.XML_LANG_SPACE_SpecNS.equals(NValue)) {
383
+ ns.addMapping(NName, NValue, attribute);
384
+ }
385
+ } else if (!"id".equals(NName) && XML_LANG_URI.equals(attribute.getNamespaceURI())) {
386
+ xmlattrStack.addXmlnsAttr(attribute);
387
+ }
388
+ }
389
+ if (e.getNamespaceURI() != null) {
390
+ String NName = e.getPrefix();
391
+ String NValue = e.getNamespaceURI();
392
+ String Name;
393
+ if (NName == null || NName.equals("")) {
394
+ NName = "xmlns";
395
+ Name = "xmlns";
396
+ } else {
397
+ Name = "xmlns:" + NName;
398
+ }
399
+ Attr n = e.getOwnerDocument().createAttributeNS("http://www.w3.org/2000/xmlns/", Name);
400
+ n.setValue(NValue);
401
+ ns.addMapping(NName, NValue, n);
402
+ }
403
+ }
404
+
405
+ private static String joinURI(String baseURI, String relativeURI) throws URISyntaxException {
406
+ String bscheme = null;
407
+ String bauthority = null;
408
+ String bpath = "";
409
+ String bquery = null;
410
+
411
+ // pre-parse the baseURI
412
+ if (baseURI != null) {
413
+ if (baseURI.endsWith("..")) {
414
+ baseURI = baseURI + "/";
415
+ }
416
+ URI base = new URI(baseURI);
417
+ bscheme = base.getScheme();
418
+ bauthority = base.getAuthority();
419
+ bpath = base.getPath();
420
+ bquery = base.getQuery();
421
+ }
422
+
423
+ URI r = new URI(relativeURI);
424
+ String rscheme = r.getScheme();
425
+ String rauthority = r.getAuthority();
426
+ String rpath = r.getPath();
427
+ String rquery = r.getQuery();
428
+
429
+ String tscheme, tauthority, tpath, tquery;
430
+ if (rscheme != null && rscheme.equals(bscheme)) {
431
+ rscheme = null;
432
+ }
433
+ if (rscheme != null) {
434
+ tscheme = rscheme;
435
+ tauthority = rauthority;
436
+ tpath = removeDotSegments(rpath);
437
+ tquery = rquery;
438
+ } else {
439
+ if (rauthority != null) {
440
+ tauthority = rauthority;
441
+ tpath = removeDotSegments(rpath);
442
+ tquery = rquery;
443
+ } else {
444
+ if (rpath.length() == 0) {
445
+ tpath = bpath;
446
+ if (rquery != null) {
447
+ tquery = rquery;
448
+ } else {
449
+ tquery = bquery;
450
+ }
451
+ } else {
452
+ if (rpath.startsWith("/")) {
453
+ tpath = removeDotSegments(rpath);
454
+ } else {
455
+ if (bauthority != null && bpath.length() == 0) {
456
+ tpath = "/" + rpath;
457
+ } else {
458
+ int last = bpath.lastIndexOf('/');
459
+ if (last == -1) {
460
+ tpath = rpath;
461
+ } else {
462
+ tpath = bpath.substring(0, last+1) + rpath;
463
+ }
464
+ }
465
+ tpath = removeDotSegments(tpath);
466
+ }
467
+ tquery = rquery;
468
+ }
469
+ tauthority = bauthority;
470
+ }
471
+ tscheme = bscheme;
472
+ }
473
+ return new URI(tscheme, tauthority, tpath, tquery, null).toString();
474
+ }
475
+
476
+ private static String removeDotSegments(String path) {
477
+
478
+ // 1. The input buffer is initialized with the now-appended path
479
+ // components then replace occurrences of "//" in the input buffer
480
+ // with "/" until no more occurrences of "//" are in the input buffer.
481
+ String input = path;
482
+ while (input.indexOf("//") > -1) {
483
+ input = input.replaceAll("//", "/");
484
+ }
485
+
486
+ // Initialize the output buffer with the empty string.
487
+ StringBuilder output = new StringBuilder();
488
+
489
+ // If the input buffer starts with a root slash "/" then move this
490
+ // character to the output buffer.
491
+ if (input.charAt(0) == '/') {
492
+ output.append('/');
493
+ input = input.substring(1);
494
+ }
495
+
496
+ printStep("1 ", output, input);
497
+
498
+ // While the input buffer is not empty, loop as follows
499
+ while (input.length() != 0) {
500
+ // 2A. If the input buffer begins with a prefix of "./",
501
+ // then remove that prefix from the input buffer
502
+ // else if the input buffer begins with a prefix of "../", then
503
+ // if also the output does not contain the root slash "/" only,
504
+ // then move this prefix to the end of the output buffer else
505
+ // remove that prefix
506
+ if (input.startsWith("./")) {
507
+ input = input.substring(2);
508
+ printStep("2A", output, input);
509
+ } else if (input.startsWith("../")) {
510
+ input = input.substring(3);
511
+ if (!output.toString().equals("/")) {
512
+ output.append("../");
513
+ }
514
+ printStep("2A", output, input);
515
+ // 2B. if the input buffer begins with a prefix of "/./" or "/.",
516
+ // where "." is a complete path segment, then replace that prefix
517
+ // with "/" in the input buffer; otherwise,
518
+ } else if (input.startsWith("/./")) {
519
+ input = input.substring(2);
520
+ printStep("2B", output, input);
521
+ } else if (input.equals("/.")) {
522
+ // FIXME: what is complete path segment?
523
+ input = input.replaceFirst("/.", "/");
524
+ printStep("2B", output, input);
525
+ // 2C. if the input buffer begins with a prefix of "/../" or "/..",
526
+ // where ".." is a complete path segment, then replace that prefix
527
+ // with "/" in the input buffer and if also the output buffer is
528
+ // empty, last segment in the output buffer equals "../" or "..",
529
+ // where ".." is a complete path segment, then append ".." or "/.."
530
+ // for the latter case respectively to the output buffer else
531
+ // remove the last segment and its preceding "/" (if any) from the
532
+ // output buffer and if hereby the first character in the output
533
+ // buffer was removed and it was not the root slash then delete a
534
+ // leading slash from the input buffer; otherwise,
535
+ } else if (input.startsWith("/../")) {
536
+ input = input.substring(3);
537
+ if (output.length() == 0) {
538
+ output.append("/");
539
+ } else if (output.toString().endsWith("../")) {
540
+ output.append("..");
541
+ } else if (output.toString().endsWith("..")) {
542
+ output.append("/..");
543
+ } else {
544
+ int index = output.lastIndexOf("/");
545
+ if (index == -1) {
546
+ output = new StringBuilder();
547
+ if (input.charAt(0) == '/') {
548
+ input = input.substring(1);
549
+ }
550
+ } else {
551
+ output = output.delete(index, output.length());
552
+ }
553
+ }
554
+ printStep("2C", output, input);
555
+ } else if (input.equals("/..")) {
556
+ // FIXME: what is complete path segment?
557
+ input = input.replaceFirst("/..", "/");
558
+ if (output.length() == 0) {
559
+ output.append("/");
560
+ } else if (output.toString().endsWith("../")) {
561
+ output.append("..");
562
+ } else if (output.toString().endsWith("..")) {
563
+ output.append("/..");
564
+ } else {
565
+ int index = output.lastIndexOf("/");
566
+ if (index == -1) {
567
+ output = new StringBuilder();
568
+ if (input.charAt(0) == '/') {
569
+ input = input.substring(1);
570
+ }
571
+ } else {
572
+ output = output.delete(index, output.length());
573
+ }
574
+ }
575
+ printStep("2C", output, input);
576
+ // 2D. if the input buffer consists only of ".", then remove
577
+ // that from the input buffer else if the input buffer consists
578
+ // only of ".." and if the output buffer does not contain only
579
+ // the root slash "/", then move the ".." to the output buffer
580
+ // else delte it.; otherwise,
581
+ } else if (input.equals(".")) {
582
+ input = "";
583
+ printStep("2D", output, input);
584
+ } else if (input.equals("..")) {
585
+ if (!output.toString().equals("/")) {
586
+ output.append("..");
587
+ }
588
+ input = "";
589
+ printStep("2D", output, input);
590
+ // 2E. move the first path segment (if any) in the input buffer
591
+ // to the end of the output buffer, including the initial "/"
592
+ // character (if any) and any subsequent characters up to, but not
593
+ // including, the next "/" character or the end of the input buffer.
594
+ } else {
595
+ int end;
596
+ int begin = input.indexOf('/');
597
+ if (begin == 0) {
598
+ end = input.indexOf('/', 1);
599
+ } else {
600
+ end = begin;
601
+ begin = 0;
602
+ }
603
+ String segment;
604
+ if (end == -1) {
605
+ segment = input.substring(begin);
606
+ input = "";
607
+ } else {
608
+ segment = input.substring(begin, end);
609
+ input = input.substring(end);
610
+ }
611
+ output.append(segment);
612
+ printStep("2E", output, input);
613
+ }
614
+ }
615
+
616
+ // 3. Finally, if the only or last segment of the output buffer is
617
+ // "..", where ".." is a complete path segment not followed by a slash
618
+ // then append a slash "/". The output buffer is returned as the result
619
+ // of remove_dot_segments
620
+ if (output.toString().endsWith("..")) {
621
+ output.append('/');
622
+ printStep("3 ", output, input);
623
+ }
624
+
625
+ return output.toString();
626
+ }
627
+
628
+ private static void printStep(String step, StringBuilder output, String input) {
629
+ //if (System.getProperty("nokogiri.c14.debug") == "on") { //
630
+ // System.out.println(" " + step + ": " + output);
631
+ // if (output.length() == 0) {
632
+ // System.out.println("\t\t\t\t" + input);
633
+ // } else {
634
+ // System.out.println("\t\t\t" + input);
635
+ // }
636
+ //}
637
+ }
638
+
639
+ }
@@ -0,0 +1,38 @@
1
+ /**
2
+ * Licensed to the Apache Software Foundation (ASF) under one
3
+ * or more contributor license agreements. See the NOTICE file
4
+ * distributed with this work for additional information
5
+ * regarding copyright ownership. The ASF licenses this file
6
+ * to you under the Apache License, Version 2.0 (the
7
+ * "License"); you may not use this file except in compliance
8
+ * with the License. You may obtain a copy of the License at
9
+ *
10
+ * http://www.apache.org/licenses/LICENSE-2.0
11
+ *
12
+ * Unless required by applicable law or agreed to in writing,
13
+ * software distributed under the License is distributed on an
14
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15
+ * KIND, either express or implied. See the License for the
16
+ * specific language governing permissions and limitations
17
+ * under the License.
18
+ */
19
+ package nokogiri.internals.c14n;
20
+
21
+
22
+ /**
23
+ * @author Sean Mullan
24
+ */
25
+ public class Canonicalizer11_OmitComments extends Canonicalizer11 {
26
+
27
+ public Canonicalizer11_OmitComments() {
28
+ super(false);
29
+ }
30
+
31
+ public final String engineGetURI() {
32
+ return Canonicalizer.ALGO_ID_C14N11_OMIT_COMMENTS;
33
+ }
34
+
35
+ public final boolean engineGetIncludeComments() {
36
+ return false;
37
+ }
38
+ }