nokogiri-backport 1.11.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Gemfile +3 -0
- data/LICENSE-DEPENDENCIES.md +1682 -0
- data/LICENSE.md +9 -0
- data/README.md +272 -0
- data/bin/nokogiri +118 -0
- data/dependencies.yml +74 -0
- data/ext/java/nokogiri/EncodingHandler.java +124 -0
- data/ext/java/nokogiri/HtmlDocument.java +178 -0
- data/ext/java/nokogiri/HtmlElementDescription.java +148 -0
- data/ext/java/nokogiri/HtmlEntityLookup.java +79 -0
- data/ext/java/nokogiri/HtmlSaxParserContext.java +282 -0
- data/ext/java/nokogiri/HtmlSaxPushParser.java +222 -0
- data/ext/java/nokogiri/NokogiriService.java +597 -0
- data/ext/java/nokogiri/XmlAttr.java +162 -0
- data/ext/java/nokogiri/XmlAttributeDecl.java +129 -0
- data/ext/java/nokogiri/XmlCdata.java +82 -0
- data/ext/java/nokogiri/XmlComment.java +97 -0
- data/ext/java/nokogiri/XmlDocument.java +633 -0
- data/ext/java/nokogiri/XmlDocumentFragment.java +185 -0
- data/ext/java/nokogiri/XmlDtd.java +481 -0
- data/ext/java/nokogiri/XmlElement.java +68 -0
- data/ext/java/nokogiri/XmlElementContent.java +382 -0
- data/ext/java/nokogiri/XmlElementDecl.java +147 -0
- data/ext/java/nokogiri/XmlEntityDecl.java +157 -0
- data/ext/java/nokogiri/XmlEntityReference.java +101 -0
- data/ext/java/nokogiri/XmlNamespace.java +199 -0
- data/ext/java/nokogiri/XmlNode.java +1684 -0
- data/ext/java/nokogiri/XmlNodeSet.java +434 -0
- data/ext/java/nokogiri/XmlProcessingInstruction.java +100 -0
- data/ext/java/nokogiri/XmlReader.java +531 -0
- data/ext/java/nokogiri/XmlRelaxng.java +151 -0
- data/ext/java/nokogiri/XmlSaxParserContext.java +374 -0
- data/ext/java/nokogiri/XmlSaxPushParser.java +286 -0
- data/ext/java/nokogiri/XmlSchema.java +388 -0
- data/ext/java/nokogiri/XmlSyntaxError.java +138 -0
- data/ext/java/nokogiri/XmlText.java +110 -0
- data/ext/java/nokogiri/XmlXpathContext.java +301 -0
- data/ext/java/nokogiri/XsltStylesheet.java +347 -0
- data/ext/java/nokogiri/internals/ClosedStreamException.java +10 -0
- data/ext/java/nokogiri/internals/HtmlDomParserContext.java +252 -0
- data/ext/java/nokogiri/internals/IgnoreSchemaErrorsErrorHandler.java +20 -0
- data/ext/java/nokogiri/internals/NokogiriBlockingQueueInputStream.java +151 -0
- data/ext/java/nokogiri/internals/NokogiriDomParser.java +116 -0
- data/ext/java/nokogiri/internals/NokogiriEntityResolver.java +121 -0
- data/ext/java/nokogiri/internals/NokogiriErrorHandler.java +69 -0
- data/ext/java/nokogiri/internals/NokogiriHandler.java +327 -0
- data/ext/java/nokogiri/internals/NokogiriHelpers.java +734 -0
- data/ext/java/nokogiri/internals/NokogiriNamespaceCache.java +217 -0
- data/ext/java/nokogiri/internals/NokogiriNamespaceContext.java +127 -0
- data/ext/java/nokogiri/internals/NokogiriNonStrictErrorHandler.java +100 -0
- data/ext/java/nokogiri/internals/NokogiriNonStrictErrorHandler4NekoHtml.java +121 -0
- data/ext/java/nokogiri/internals/NokogiriStrictErrorHandler.java +78 -0
- data/ext/java/nokogiri/internals/NokogiriXPathFunction.java +180 -0
- data/ext/java/nokogiri/internals/NokogiriXPathFunctionResolver.java +72 -0
- data/ext/java/nokogiri/internals/NokogiriXPathVariableResolver.java +60 -0
- data/ext/java/nokogiri/internals/NokogiriXsltErrorListener.java +87 -0
- data/ext/java/nokogiri/internals/ParserContext.java +259 -0
- data/ext/java/nokogiri/internals/ReaderNode.java +488 -0
- data/ext/java/nokogiri/internals/SaveContextVisitor.java +778 -0
- data/ext/java/nokogiri/internals/SchemaErrorHandler.java +73 -0
- data/ext/java/nokogiri/internals/XalanDTMManagerPatch.java +168 -0
- data/ext/java/nokogiri/internals/XmlDeclHandler.java +42 -0
- data/ext/java/nokogiri/internals/XmlDomParserContext.java +274 -0
- data/ext/java/nokogiri/internals/XmlSaxParser.java +65 -0
- data/ext/java/nokogiri/internals/c14n/AttrCompare.java +119 -0
- data/ext/java/nokogiri/internals/c14n/C14nHelper.java +159 -0
- data/ext/java/nokogiri/internals/c14n/CanonicalFilter.java +37 -0
- data/ext/java/nokogiri/internals/c14n/CanonicalizationException.java +93 -0
- data/ext/java/nokogiri/internals/c14n/Canonicalizer.java +252 -0
- data/ext/java/nokogiri/internals/c14n/Canonicalizer11.java +639 -0
- data/ext/java/nokogiri/internals/c14n/Canonicalizer11_OmitComments.java +38 -0
- data/ext/java/nokogiri/internals/c14n/Canonicalizer11_WithComments.java +38 -0
- data/ext/java/nokogiri/internals/c14n/Canonicalizer20010315.java +367 -0
- data/ext/java/nokogiri/internals/c14n/Canonicalizer20010315Excl.java +295 -0
- data/ext/java/nokogiri/internals/c14n/Canonicalizer20010315ExclOmitComments.java +40 -0
- data/ext/java/nokogiri/internals/c14n/Canonicalizer20010315ExclWithComments.java +44 -0
- data/ext/java/nokogiri/internals/c14n/Canonicalizer20010315OmitComments.java +44 -0
- data/ext/java/nokogiri/internals/c14n/Canonicalizer20010315WithComments.java +43 -0
- data/ext/java/nokogiri/internals/c14n/CanonicalizerBase.java +630 -0
- data/ext/java/nokogiri/internals/c14n/CanonicalizerPhysical.java +173 -0
- data/ext/java/nokogiri/internals/c14n/CanonicalizerSpi.java +76 -0
- data/ext/java/nokogiri/internals/c14n/Constants.java +42 -0
- data/ext/java/nokogiri/internals/c14n/ElementProxy.java +293 -0
- data/ext/java/nokogiri/internals/c14n/HelperNodeList.java +93 -0
- data/ext/java/nokogiri/internals/c14n/IgnoreAllErrorHandler.java +79 -0
- data/ext/java/nokogiri/internals/c14n/InclusiveNamespaces.java +166 -0
- data/ext/java/nokogiri/internals/c14n/InvalidCanonicalizerException.java +76 -0
- data/ext/java/nokogiri/internals/c14n/NameSpaceSymbTable.java +402 -0
- data/ext/java/nokogiri/internals/c14n/NodeFilter.java +51 -0
- data/ext/java/nokogiri/internals/c14n/UtfHelpper.java +179 -0
- data/ext/java/nokogiri/internals/c14n/XMLUtils.java +507 -0
- data/ext/java/nokogiri/internals/dom2dtm/DOM2DTM.java +1745 -0
- data/ext/java/nokogiri/internals/dom2dtm/DOM2DTMdefaultNamespaceDeclarationNode.java +685 -0
- data/ext/nokogiri/depend +477 -0
- data/ext/nokogiri/extconf.rb +836 -0
- data/ext/nokogiri/html_document.c +171 -0
- data/ext/nokogiri/html_document.h +10 -0
- data/ext/nokogiri/html_element_description.c +279 -0
- data/ext/nokogiri/html_element_description.h +10 -0
- data/ext/nokogiri/html_entity_lookup.c +32 -0
- data/ext/nokogiri/html_entity_lookup.h +8 -0
- data/ext/nokogiri/html_sax_parser_context.c +116 -0
- data/ext/nokogiri/html_sax_parser_context.h +11 -0
- data/ext/nokogiri/html_sax_push_parser.c +87 -0
- data/ext/nokogiri/html_sax_push_parser.h +9 -0
- data/ext/nokogiri/nokogiri.c +135 -0
- data/ext/nokogiri/nokogiri.h +130 -0
- data/ext/nokogiri/xml_attr.c +103 -0
- data/ext/nokogiri/xml_attr.h +9 -0
- data/ext/nokogiri/xml_attribute_decl.c +70 -0
- data/ext/nokogiri/xml_attribute_decl.h +9 -0
- data/ext/nokogiri/xml_cdata.c +62 -0
- data/ext/nokogiri/xml_cdata.h +9 -0
- data/ext/nokogiri/xml_comment.c +69 -0
- data/ext/nokogiri/xml_comment.h +9 -0
- data/ext/nokogiri/xml_document.c +622 -0
- data/ext/nokogiri/xml_document.h +23 -0
- data/ext/nokogiri/xml_document_fragment.c +48 -0
- data/ext/nokogiri/xml_document_fragment.h +10 -0
- data/ext/nokogiri/xml_dtd.c +202 -0
- data/ext/nokogiri/xml_dtd.h +10 -0
- data/ext/nokogiri/xml_element_content.c +123 -0
- data/ext/nokogiri/xml_element_content.h +10 -0
- data/ext/nokogiri/xml_element_decl.c +69 -0
- data/ext/nokogiri/xml_element_decl.h +9 -0
- data/ext/nokogiri/xml_encoding_handler.c +79 -0
- data/ext/nokogiri/xml_encoding_handler.h +8 -0
- data/ext/nokogiri/xml_entity_decl.c +110 -0
- data/ext/nokogiri/xml_entity_decl.h +10 -0
- data/ext/nokogiri/xml_entity_reference.c +52 -0
- data/ext/nokogiri/xml_entity_reference.h +9 -0
- data/ext/nokogiri/xml_io.c +63 -0
- data/ext/nokogiri/xml_io.h +11 -0
- data/ext/nokogiri/xml_libxml2_hacks.c +112 -0
- data/ext/nokogiri/xml_libxml2_hacks.h +12 -0
- data/ext/nokogiri/xml_namespace.c +111 -0
- data/ext/nokogiri/xml_namespace.h +14 -0
- data/ext/nokogiri/xml_node.c +1773 -0
- data/ext/nokogiri/xml_node.h +13 -0
- data/ext/nokogiri/xml_node_set.c +486 -0
- data/ext/nokogiri/xml_node_set.h +12 -0
- data/ext/nokogiri/xml_processing_instruction.c +56 -0
- data/ext/nokogiri/xml_processing_instruction.h +9 -0
- data/ext/nokogiri/xml_reader.c +657 -0
- data/ext/nokogiri/xml_reader.h +10 -0
- data/ext/nokogiri/xml_relax_ng.c +179 -0
- data/ext/nokogiri/xml_relax_ng.h +9 -0
- data/ext/nokogiri/xml_sax_parser.c +305 -0
- data/ext/nokogiri/xml_sax_parser.h +39 -0
- data/ext/nokogiri/xml_sax_parser_context.c +262 -0
- data/ext/nokogiri/xml_sax_parser_context.h +10 -0
- data/ext/nokogiri/xml_sax_push_parser.c +159 -0
- data/ext/nokogiri/xml_sax_push_parser.h +9 -0
- data/ext/nokogiri/xml_schema.c +276 -0
- data/ext/nokogiri/xml_schema.h +9 -0
- data/ext/nokogiri/xml_syntax_error.c +64 -0
- data/ext/nokogiri/xml_syntax_error.h +13 -0
- data/ext/nokogiri/xml_text.c +52 -0
- data/ext/nokogiri/xml_text.h +9 -0
- data/ext/nokogiri/xml_xpath_context.c +374 -0
- data/ext/nokogiri/xml_xpath_context.h +10 -0
- data/ext/nokogiri/xslt_stylesheet.c +263 -0
- data/ext/nokogiri/xslt_stylesheet.h +14 -0
- data/lib/isorelax.jar +0 -0
- data/lib/jing.jar +0 -0
- data/lib/nekodtd.jar +0 -0
- data/lib/nekohtml.jar +0 -0
- data/lib/nokogiri/css/node.rb +53 -0
- data/lib/nokogiri/css/parser.rb +751 -0
- data/lib/nokogiri/css/parser.y +272 -0
- data/lib/nokogiri/css/parser_extras.rb +94 -0
- data/lib/nokogiri/css/syntax_error.rb +8 -0
- data/lib/nokogiri/css/tokenizer.rb +154 -0
- data/lib/nokogiri/css/tokenizer.rex +55 -0
- data/lib/nokogiri/css/xpath_visitor.rb +260 -0
- data/lib/nokogiri/css.rb +28 -0
- data/lib/nokogiri/decorators/slop.rb +43 -0
- data/lib/nokogiri/html/builder.rb +36 -0
- data/lib/nokogiri/html/document.rb +322 -0
- data/lib/nokogiri/html/document_fragment.rb +50 -0
- data/lib/nokogiri/html/element_description.rb +24 -0
- data/lib/nokogiri/html/element_description_defaults.rb +672 -0
- data/lib/nokogiri/html/entity_lookup.rb +14 -0
- data/lib/nokogiri/html/sax/parser.rb +63 -0
- data/lib/nokogiri/html/sax/parser_context.rb +17 -0
- data/lib/nokogiri/html/sax/push_parser.rb +37 -0
- data/lib/nokogiri/html.rb +38 -0
- data/lib/nokogiri/jruby/dependencies.rb +20 -0
- data/lib/nokogiri/syntax_error.rb +5 -0
- data/lib/nokogiri/version/constant.rb +5 -0
- data/lib/nokogiri/version/info.rb +182 -0
- data/lib/nokogiri/version.rb +3 -0
- data/lib/nokogiri/xml/attr.rb +15 -0
- data/lib/nokogiri/xml/attribute_decl.rb +19 -0
- data/lib/nokogiri/xml/builder.rb +447 -0
- data/lib/nokogiri/xml/cdata.rb +12 -0
- data/lib/nokogiri/xml/character_data.rb +8 -0
- data/lib/nokogiri/xml/document.rb +290 -0
- data/lib/nokogiri/xml/document_fragment.rb +159 -0
- data/lib/nokogiri/xml/dtd.rb +33 -0
- data/lib/nokogiri/xml/element_content.rb +37 -0
- data/lib/nokogiri/xml/element_decl.rb +14 -0
- data/lib/nokogiri/xml/entity_decl.rb +20 -0
- data/lib/nokogiri/xml/entity_reference.rb +19 -0
- data/lib/nokogiri/xml/namespace.rb +14 -0
- data/lib/nokogiri/xml/node/save_options.rb +62 -0
- data/lib/nokogiri/xml/node.rb +1240 -0
- data/lib/nokogiri/xml/node_set.rb +372 -0
- data/lib/nokogiri/xml/notation.rb +7 -0
- data/lib/nokogiri/xml/parse_options.rb +127 -0
- data/lib/nokogiri/xml/pp/character_data.rb +19 -0
- data/lib/nokogiri/xml/pp/node.rb +57 -0
- data/lib/nokogiri/xml/pp.rb +3 -0
- data/lib/nokogiri/xml/processing_instruction.rb +9 -0
- data/lib/nokogiri/xml/reader.rb +116 -0
- data/lib/nokogiri/xml/relax_ng.rb +37 -0
- data/lib/nokogiri/xml/sax/document.rb +172 -0
- data/lib/nokogiri/xml/sax/parser.rb +123 -0
- data/lib/nokogiri/xml/sax/parser_context.rb +17 -0
- data/lib/nokogiri/xml/sax/push_parser.rb +61 -0
- data/lib/nokogiri/xml/sax.rb +5 -0
- data/lib/nokogiri/xml/schema.rb +72 -0
- data/lib/nokogiri/xml/searchable.rb +239 -0
- data/lib/nokogiri/xml/syntax_error.rb +71 -0
- data/lib/nokogiri/xml/text.rb +10 -0
- data/lib/nokogiri/xml/xpath/syntax_error.rb +12 -0
- data/lib/nokogiri/xml/xpath.rb +11 -0
- data/lib/nokogiri/xml/xpath_context.rb +17 -0
- data/lib/nokogiri/xml.rb +76 -0
- data/lib/nokogiri/xslt/stylesheet.rb +26 -0
- data/lib/nokogiri/xslt.rb +57 -0
- data/lib/nokogiri.rb +144 -0
- data/lib/serializer.jar +0 -0
- data/lib/xalan.jar +0 -0
- data/lib/xercesImpl.jar +0 -0
- data/lib/xml-apis.jar +0 -0
- data/lib/xsd/xmlparser/nokogiri.rb +103 -0
- metadata +531 -0
@@ -0,0 +1,119 @@
|
|
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.io.Serializable;
|
22
|
+
import java.util.Comparator;
|
23
|
+
|
24
|
+
|
25
|
+
import org.w3c.dom.Attr;
|
26
|
+
|
27
|
+
/**
|
28
|
+
* Compares two attributes based on the C14n specification.
|
29
|
+
*
|
30
|
+
* <UL>
|
31
|
+
* <LI>Namespace nodes have a lesser document order position than attribute
|
32
|
+
* nodes.
|
33
|
+
* <LI> An element's namespace nodes are sorted lexicographically by
|
34
|
+
* local name (the default namespace node, if one exists, has no
|
35
|
+
* local name and is therefore lexicographically least).
|
36
|
+
* <LI> An element's attribute nodes are sorted lexicographically with
|
37
|
+
* namespace URI as the primary key and local name as the secondary
|
38
|
+
* key (an empty namespace URI is lexicographically least).
|
39
|
+
* </UL>
|
40
|
+
*
|
41
|
+
* @author Christian Geuer-Pollmann
|
42
|
+
*/
|
43
|
+
public class AttrCompare implements Comparator<Attr>, Serializable {
|
44
|
+
|
45
|
+
private static final long serialVersionUID = -7113259629930576230L;
|
46
|
+
private static final int ATTR0_BEFORE_ATTR1 = -1;
|
47
|
+
private static final int ATTR1_BEFORE_ATTR0 = 1;
|
48
|
+
private static final String XMLNS = Constants.NamespaceSpecNS;
|
49
|
+
|
50
|
+
/**
|
51
|
+
* Compares two attributes based on the C14n specification.
|
52
|
+
*
|
53
|
+
* <UL>
|
54
|
+
* <LI>Namespace nodes have a lesser document order position than
|
55
|
+
* attribute nodes.
|
56
|
+
* <LI> An element's namespace nodes are sorted lexicographically by
|
57
|
+
* local name (the default namespace node, if one exists, has no
|
58
|
+
* local name and is therefore lexicographically least).
|
59
|
+
* <LI> An element's attribute nodes are sorted lexicographically with
|
60
|
+
* namespace URI as the primary key and local name as the secondary
|
61
|
+
* key (an empty namespace URI is lexicographically least).
|
62
|
+
* </UL>
|
63
|
+
*
|
64
|
+
* @param attr0
|
65
|
+
* @param attr1
|
66
|
+
* @return returns a negative integer, zero, or a positive integer as
|
67
|
+
* obj0 is less than, equal to, or greater than obj1
|
68
|
+
*
|
69
|
+
*/
|
70
|
+
public int compare(Attr attr0, Attr attr1) {
|
71
|
+
String namespaceURI0 = attr0.getNamespaceURI();
|
72
|
+
String namespaceURI1 = attr1.getNamespaceURI();
|
73
|
+
|
74
|
+
boolean isNamespaceAttr0 = XMLNS.equals(namespaceURI0);
|
75
|
+
boolean isNamespaceAttr1 = XMLNS.equals(namespaceURI1);
|
76
|
+
|
77
|
+
if (isNamespaceAttr0) {
|
78
|
+
if (isNamespaceAttr1) {
|
79
|
+
// both are namespaces
|
80
|
+
String localname0 = attr0.getLocalName();
|
81
|
+
String localname1 = attr1.getLocalName();
|
82
|
+
|
83
|
+
if ("xmlns".equals(localname0)) {
|
84
|
+
localname0 = "";
|
85
|
+
}
|
86
|
+
|
87
|
+
if ("xmlns".equals(localname1)) {
|
88
|
+
localname1 = "";
|
89
|
+
}
|
90
|
+
|
91
|
+
return localname0.compareTo(localname1);
|
92
|
+
}
|
93
|
+
// attr0 is a namespace, attr1 is not
|
94
|
+
return ATTR0_BEFORE_ATTR1;
|
95
|
+
} else if (isNamespaceAttr1) {
|
96
|
+
// attr1 is a namespace, attr0 is not
|
97
|
+
return ATTR1_BEFORE_ATTR0;
|
98
|
+
}
|
99
|
+
|
100
|
+
// none is a namespace
|
101
|
+
if (namespaceURI0 == null) {
|
102
|
+
if (namespaceURI1 == null) {
|
103
|
+
String name0 = attr0.getName();
|
104
|
+
String name1 = attr1.getName();
|
105
|
+
return name0.compareTo(name1);
|
106
|
+
}
|
107
|
+
return ATTR0_BEFORE_ATTR1;
|
108
|
+
} else if (namespaceURI1 == null) {
|
109
|
+
return ATTR1_BEFORE_ATTR0;
|
110
|
+
}
|
111
|
+
|
112
|
+
int a = namespaceURI0.compareTo(namespaceURI1);
|
113
|
+
if (a != 0) {
|
114
|
+
return a;
|
115
|
+
}
|
116
|
+
|
117
|
+
return (attr0.getLocalName()).compareTo(attr1.getLocalName());
|
118
|
+
}
|
119
|
+
}
|
@@ -0,0 +1,159 @@
|
|
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
|
+
import org.w3c.dom.Attr;
|
23
|
+
import org.w3c.dom.Document;
|
24
|
+
import org.w3c.dom.Element;
|
25
|
+
import org.w3c.dom.NamedNodeMap;
|
26
|
+
|
27
|
+
/**
|
28
|
+
* Temporary swapped static functions from the normalizer Section
|
29
|
+
*
|
30
|
+
* @author Christian Geuer-Pollmann
|
31
|
+
*/
|
32
|
+
public class C14nHelper {
|
33
|
+
|
34
|
+
/**
|
35
|
+
* Constructor C14nHelper
|
36
|
+
*
|
37
|
+
*/
|
38
|
+
private C14nHelper() {
|
39
|
+
// don't allow instantiation
|
40
|
+
}
|
41
|
+
|
42
|
+
/**
|
43
|
+
* Method namespaceIsRelative
|
44
|
+
*
|
45
|
+
* @param namespace
|
46
|
+
* @return true if the given namespace is relative.
|
47
|
+
*/
|
48
|
+
public static boolean namespaceIsRelative(Attr namespace) {
|
49
|
+
return !namespaceIsAbsolute(namespace);
|
50
|
+
}
|
51
|
+
|
52
|
+
/**
|
53
|
+
* Method namespaceIsRelative
|
54
|
+
*
|
55
|
+
* @param namespaceValue
|
56
|
+
* @return true if the given namespace is relative.
|
57
|
+
*/
|
58
|
+
public static boolean namespaceIsRelative(String namespaceValue) {
|
59
|
+
return !namespaceIsAbsolute(namespaceValue);
|
60
|
+
}
|
61
|
+
|
62
|
+
/**
|
63
|
+
* Method namespaceIsAbsolute
|
64
|
+
*
|
65
|
+
* @param namespace
|
66
|
+
* @return true if the given namespace is absolute.
|
67
|
+
*/
|
68
|
+
public static boolean namespaceIsAbsolute(Attr namespace) {
|
69
|
+
return namespaceIsAbsolute(namespace.getValue());
|
70
|
+
}
|
71
|
+
|
72
|
+
/**
|
73
|
+
* Method namespaceIsAbsolute
|
74
|
+
*
|
75
|
+
* @param namespaceValue
|
76
|
+
* @return true if the given namespace is absolute.
|
77
|
+
*/
|
78
|
+
public static boolean namespaceIsAbsolute(String namespaceValue) {
|
79
|
+
// assume empty namespaces are absolute
|
80
|
+
if (namespaceValue.length() == 0) {
|
81
|
+
return true;
|
82
|
+
}
|
83
|
+
return namespaceValue.indexOf(':') > 0;
|
84
|
+
}
|
85
|
+
|
86
|
+
/**
|
87
|
+
* This method throws an exception if the Attribute value contains
|
88
|
+
* a relative URI.
|
89
|
+
*
|
90
|
+
* @param attr
|
91
|
+
* @throws CanonicalizationException
|
92
|
+
*/
|
93
|
+
public static void assertNotRelativeNS(Attr attr) throws CanonicalizationException {
|
94
|
+
if (attr == null) {
|
95
|
+
return;
|
96
|
+
}
|
97
|
+
|
98
|
+
String nodeAttrName = attr.getNodeName();
|
99
|
+
boolean definesDefaultNS = nodeAttrName.equals("xmlns");
|
100
|
+
boolean definesNonDefaultNS = nodeAttrName.startsWith("xmlns:");
|
101
|
+
|
102
|
+
if ((definesDefaultNS || definesNonDefaultNS) && namespaceIsRelative(attr)) {
|
103
|
+
String parentName = attr.getOwnerElement().getTagName();
|
104
|
+
String attrValue = attr.getValue();
|
105
|
+
Object exArgs[] = { parentName, nodeAttrName, attrValue };
|
106
|
+
|
107
|
+
throw new CanonicalizationException(
|
108
|
+
"c14n.Canonicalizer.RelativeNamespace", exArgs
|
109
|
+
);
|
110
|
+
}
|
111
|
+
}
|
112
|
+
|
113
|
+
/**
|
114
|
+
* This method throws a CanonicalizationException if the supplied Document
|
115
|
+
* is not able to be traversed using a TreeWalker.
|
116
|
+
*
|
117
|
+
* @param document
|
118
|
+
* @throws CanonicalizationException
|
119
|
+
*/
|
120
|
+
public static void checkTraversability(Document document)
|
121
|
+
throws CanonicalizationException {
|
122
|
+
if (!document.isSupported("Traversal", "2.0")) {
|
123
|
+
Object exArgs[] = {document.getImplementation().getClass().getName() };
|
124
|
+
|
125
|
+
throw new CanonicalizationException(
|
126
|
+
"c14n.Canonicalizer.TraversalNotSupported", exArgs
|
127
|
+
);
|
128
|
+
}
|
129
|
+
}
|
130
|
+
|
131
|
+
/**
|
132
|
+
* This method throws a CanonicalizationException if the supplied Element
|
133
|
+
* contains any relative namespaces.
|
134
|
+
*
|
135
|
+
* @param ctxNode
|
136
|
+
* @throws CanonicalizationException
|
137
|
+
* @see C14nHelper#assertNotRelativeNS(Attr)
|
138
|
+
*/
|
139
|
+
public static void checkForRelativeNamespace(Element ctxNode)
|
140
|
+
throws CanonicalizationException {
|
141
|
+
if (ctxNode != null) {
|
142
|
+
NamedNodeMap attributes = ctxNode.getAttributes();
|
143
|
+
|
144
|
+
for (int i = 0; i < attributes.getLength(); i++) {
|
145
|
+
C14nHelper.assertNotRelativeNS((Attr) attributes.item(i));
|
146
|
+
}
|
147
|
+
} else {
|
148
|
+
throw new CanonicalizationException("Called checkForRelativeNamespace() on null");
|
149
|
+
}
|
150
|
+
}
|
151
|
+
|
152
|
+
public static String getErrorMessage(String message, Object... exArgs) {
|
153
|
+
StringBuffer sb = new StringBuffer(message);
|
154
|
+
for (Object arg : exArgs) {
|
155
|
+
sb.append(", ").append(arg.toString());
|
156
|
+
}
|
157
|
+
return new String(sb);
|
158
|
+
}
|
159
|
+
}
|
@@ -0,0 +1,37 @@
|
|
1
|
+
package nokogiri.internals.c14n;
|
2
|
+
|
3
|
+
import nokogiri.XmlNode;
|
4
|
+
import nokogiri.internals.NokogiriHelpers;
|
5
|
+
|
6
|
+
import org.jruby.runtime.Block;
|
7
|
+
import org.jruby.runtime.ThreadContext;
|
8
|
+
import org.jruby.runtime.builtin.IRubyObject;
|
9
|
+
import org.w3c.dom.Node;
|
10
|
+
|
11
|
+
public class CanonicalFilter {
|
12
|
+
private final Block block;
|
13
|
+
private final ThreadContext context;
|
14
|
+
|
15
|
+
public CanonicalFilter(ThreadContext context, Block block) {
|
16
|
+
this.context = context;
|
17
|
+
this.block = block;
|
18
|
+
}
|
19
|
+
|
20
|
+
public boolean includeNodes(Node currentNode, Node parentNode) {
|
21
|
+
if (block == null || !block.isGiven())
|
22
|
+
return true;
|
23
|
+
|
24
|
+
IRubyObject current = NokogiriHelpers.getCachedNodeOrCreate(context.getRuntime(), currentNode);
|
25
|
+
IRubyObject parent = NokogiriHelpers.getCachedNodeOrCreate(context.getRuntime(), parentNode);
|
26
|
+
|
27
|
+
if (parent.isNil()) {
|
28
|
+
IRubyObject doc = ((XmlNode) current).document(context);
|
29
|
+
boolean returnValue = block.call(context, current, doc).isTrue();
|
30
|
+
block.call(context, doc, context.nil);
|
31
|
+
return returnValue;
|
32
|
+
}
|
33
|
+
|
34
|
+
return block.call(context, current, parent).isTrue();
|
35
|
+
}
|
36
|
+
|
37
|
+
}
|
@@ -0,0 +1,93 @@
|
|
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
|
+
* Class CanonicalizationException
|
24
|
+
*
|
25
|
+
* @author Christian Geuer-Pollmann
|
26
|
+
*/
|
27
|
+
public class CanonicalizationException extends Exception {
|
28
|
+
|
29
|
+
/**
|
30
|
+
*
|
31
|
+
*/
|
32
|
+
private static final long serialVersionUID = 1L;
|
33
|
+
|
34
|
+
/**
|
35
|
+
* Constructor CanonicalizationException
|
36
|
+
*
|
37
|
+
*/
|
38
|
+
public CanonicalizationException() {
|
39
|
+
super();
|
40
|
+
}
|
41
|
+
|
42
|
+
/**
|
43
|
+
* Constructor CanonicalizationException
|
44
|
+
*
|
45
|
+
* @param message
|
46
|
+
*/
|
47
|
+
public CanonicalizationException(String message) {
|
48
|
+
super(message);
|
49
|
+
}
|
50
|
+
|
51
|
+
/**
|
52
|
+
* Constructor CanonicalizationException
|
53
|
+
*
|
54
|
+
* @param message
|
55
|
+
* @param rootCause
|
56
|
+
*/
|
57
|
+
public CanonicalizationException(Exception rootCause) {
|
58
|
+
super(rootCause);
|
59
|
+
}
|
60
|
+
|
61
|
+
/**
|
62
|
+
* Constructor CanonicalizationException
|
63
|
+
*
|
64
|
+
* @param msgID
|
65
|
+
* @param exArgs
|
66
|
+
*/
|
67
|
+
public CanonicalizationException(String message, Object... exArgs) {
|
68
|
+
super(C14nHelper.getErrorMessage(message, exArgs));
|
69
|
+
}
|
70
|
+
|
71
|
+
/**
|
72
|
+
* Constructor CanonicalizationException
|
73
|
+
*
|
74
|
+
* @param message
|
75
|
+
* @param rootCause
|
76
|
+
*/
|
77
|
+
public CanonicalizationException(String message, Exception rootCause) {
|
78
|
+
super(message, rootCause);
|
79
|
+
}
|
80
|
+
|
81
|
+
/**
|
82
|
+
* Constructor CanonicalizationException
|
83
|
+
*
|
84
|
+
* @param msgID
|
85
|
+
* @param exArgs
|
86
|
+
* @param originalException
|
87
|
+
*/
|
88
|
+
public CanonicalizationException(String message, Exception rootCause, Object... exArgs) {
|
89
|
+
super(C14nHelper.getErrorMessage(message, exArgs), rootCause);
|
90
|
+
}
|
91
|
+
|
92
|
+
|
93
|
+
}
|
@@ -0,0 +1,252 @@
|
|
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.io.OutputStream;
|
22
|
+
import java.util.Map;
|
23
|
+
import java.util.concurrent.ConcurrentHashMap;
|
24
|
+
|
25
|
+
import org.w3c.dom.Node;
|
26
|
+
|
27
|
+
/**
|
28
|
+
*
|
29
|
+
* @author Christian Geuer-Pollmann
|
30
|
+
*/
|
31
|
+
public class Canonicalizer {
|
32
|
+
|
33
|
+
/** The output encoding of canonicalized data */
|
34
|
+
public static final String ENCODING = "UTF8";
|
35
|
+
|
36
|
+
/**
|
37
|
+
* XPath Expression for selecting every node and continuous comments joined
|
38
|
+
* in only one node
|
39
|
+
*/
|
40
|
+
public static final String XPATH_C14N_WITH_COMMENTS_SINGLE_NODE =
|
41
|
+
"(.//. | .//@* | .//namespace::*)";
|
42
|
+
|
43
|
+
/**
|
44
|
+
* The URL defined in XML-SEC Rec for inclusive c14n <b>without</b> comments.
|
45
|
+
*/
|
46
|
+
public static final String ALGO_ID_C14N_OMIT_COMMENTS =
|
47
|
+
"http://www.w3.org/TR/2001/REC-xml-c14n-20010315";
|
48
|
+
/**
|
49
|
+
* The URL defined in XML-SEC Rec for inclusive c14n <b>with</b> comments.
|
50
|
+
*/
|
51
|
+
public static final String ALGO_ID_C14N_WITH_COMMENTS =
|
52
|
+
ALGO_ID_C14N_OMIT_COMMENTS + "#WithComments";
|
53
|
+
/**
|
54
|
+
* The URL defined in XML-SEC Rec for exclusive c14n <b>without</b> comments.
|
55
|
+
*/
|
56
|
+
public static final String ALGO_ID_C14N_EXCL_OMIT_COMMENTS =
|
57
|
+
"http://www.w3.org/2001/10/xml-exc-c14n#";
|
58
|
+
/**
|
59
|
+
* The URL defined in XML-SEC Rec for exclusive c14n <b>with</b> comments.
|
60
|
+
*/
|
61
|
+
public static final String ALGO_ID_C14N_EXCL_WITH_COMMENTS =
|
62
|
+
ALGO_ID_C14N_EXCL_OMIT_COMMENTS + "WithComments";
|
63
|
+
/**
|
64
|
+
* The URI for inclusive c14n 1.1 <b>without</b> comments.
|
65
|
+
*/
|
66
|
+
public static final String ALGO_ID_C14N11_OMIT_COMMENTS =
|
67
|
+
"http://www.w3.org/2006/12/xml-c14n11";
|
68
|
+
/**
|
69
|
+
* The URI for inclusive c14n 1.1 <b>with</b> comments.
|
70
|
+
*/
|
71
|
+
public static final String ALGO_ID_C14N11_WITH_COMMENTS =
|
72
|
+
ALGO_ID_C14N11_OMIT_COMMENTS + "#WithComments";
|
73
|
+
/**
|
74
|
+
* Non-standard algorithm to serialize the physical representation for XML Encryption
|
75
|
+
*/
|
76
|
+
public static final String ALGO_ID_C14N_PHYSICAL =
|
77
|
+
"http://santuario.apache.org/c14n/physical";
|
78
|
+
|
79
|
+
private static Map<String, Class<? extends CanonicalizerSpi>> canonicalizerHash = null;
|
80
|
+
|
81
|
+
private final CanonicalizerSpi canonicalizerSpi;
|
82
|
+
|
83
|
+
/**
|
84
|
+
* Constructor Canonicalizer
|
85
|
+
*
|
86
|
+
* @param algorithmURI
|
87
|
+
* @throws InvalidCanonicalizerException
|
88
|
+
*/
|
89
|
+
private Canonicalizer(String algorithmURI) throws CanonicalizationException {
|
90
|
+
try {
|
91
|
+
Class<? extends CanonicalizerSpi> implementingClass =
|
92
|
+
canonicalizerHash.get(algorithmURI);
|
93
|
+
|
94
|
+
canonicalizerSpi = implementingClass.newInstance();
|
95
|
+
canonicalizerSpi.reset = true;
|
96
|
+
} catch (Exception e) {
|
97
|
+
Object exArgs[] = { algorithmURI };
|
98
|
+
throw new CanonicalizationException(
|
99
|
+
"signature.Canonicalizer.UnknownCanonicalizer", exArgs, e
|
100
|
+
);
|
101
|
+
}
|
102
|
+
}
|
103
|
+
|
104
|
+
/**
|
105
|
+
* Method getInstance
|
106
|
+
*
|
107
|
+
* @param algorithmURI
|
108
|
+
* @return a Canonicalizer instance ready for the job
|
109
|
+
* @throws InvalidCanonicalizerException
|
110
|
+
*/
|
111
|
+
public static final Canonicalizer getInstance(String algorithmURI)
|
112
|
+
throws CanonicalizationException {
|
113
|
+
if (canonicalizerHash == null) {
|
114
|
+
canonicalizerHash = new ConcurrentHashMap<String, Class<? extends CanonicalizerSpi>>();
|
115
|
+
Canonicalizer.registerDefaultAlgorithms();
|
116
|
+
}
|
117
|
+
return new Canonicalizer(algorithmURI);
|
118
|
+
}
|
119
|
+
|
120
|
+
/**
|
121
|
+
* Method register
|
122
|
+
*
|
123
|
+
* @param algorithmURI
|
124
|
+
* @param implementingClass
|
125
|
+
* @throws CanonicalizationException
|
126
|
+
*/
|
127
|
+
@SuppressWarnings("unchecked")
|
128
|
+
public static void register(String algorithmURI, String implementingClass)
|
129
|
+
throws CanonicalizationException, ClassNotFoundException {
|
130
|
+
// check whether URI is already registered
|
131
|
+
Class<? extends CanonicalizerSpi> registeredClass =
|
132
|
+
canonicalizerHash.get(algorithmURI);
|
133
|
+
|
134
|
+
if (registeredClass != null) {
|
135
|
+
Object exArgs[] = { algorithmURI, registeredClass };
|
136
|
+
throw new CanonicalizationException("algorithm.alreadyRegistered", exArgs);
|
137
|
+
}
|
138
|
+
|
139
|
+
canonicalizerHash.put(
|
140
|
+
algorithmURI, (Class<? extends CanonicalizerSpi>)Class.forName(implementingClass)
|
141
|
+
);
|
142
|
+
}
|
143
|
+
|
144
|
+
/**
|
145
|
+
* Method register
|
146
|
+
*
|
147
|
+
* @param algorithmURI
|
148
|
+
* @param implementingClass
|
149
|
+
* @throws CanonicalizationException
|
150
|
+
*/
|
151
|
+
public static void register(String algorithmURI, Class<? extends CanonicalizerSpi> implementingClass)
|
152
|
+
throws CanonicalizationException {
|
153
|
+
// check whether URI is already registered
|
154
|
+
Class<? extends CanonicalizerSpi> registeredClass = canonicalizerHash.get(algorithmURI);
|
155
|
+
|
156
|
+
if (registeredClass != null) {
|
157
|
+
Object exArgs[] = { algorithmURI, registeredClass };
|
158
|
+
throw new CanonicalizationException("algorithm.alreadyRegistered", exArgs);
|
159
|
+
}
|
160
|
+
|
161
|
+
canonicalizerHash.put(algorithmURI, implementingClass);
|
162
|
+
}
|
163
|
+
|
164
|
+
/**
|
165
|
+
* This method registers the default algorithms.
|
166
|
+
*/
|
167
|
+
private static void registerDefaultAlgorithms() {
|
168
|
+
canonicalizerHash.put(Canonicalizer.ALGO_ID_C14N_OMIT_COMMENTS,
|
169
|
+
Canonicalizer20010315OmitComments.class);
|
170
|
+
canonicalizerHash.put(Canonicalizer.ALGO_ID_C14N_WITH_COMMENTS,
|
171
|
+
Canonicalizer20010315WithComments.class);
|
172
|
+
canonicalizerHash.put(Canonicalizer.ALGO_ID_C14N_EXCL_OMIT_COMMENTS,
|
173
|
+
Canonicalizer20010315ExclOmitComments.class);
|
174
|
+
canonicalizerHash.put(Canonicalizer.ALGO_ID_C14N_EXCL_WITH_COMMENTS,
|
175
|
+
Canonicalizer20010315ExclWithComments.class);
|
176
|
+
canonicalizerHash.put(Canonicalizer.ALGO_ID_C14N11_OMIT_COMMENTS,
|
177
|
+
Canonicalizer11_OmitComments.class);
|
178
|
+
canonicalizerHash.put(Canonicalizer.ALGO_ID_C14N11_WITH_COMMENTS,
|
179
|
+
Canonicalizer11_WithComments.class);
|
180
|
+
canonicalizerHash.put(Canonicalizer.ALGO_ID_C14N_PHYSICAL,
|
181
|
+
CanonicalizerPhysical.class);
|
182
|
+
}
|
183
|
+
|
184
|
+
/**
|
185
|
+
* Method getURI
|
186
|
+
*
|
187
|
+
* @return the URI defined for this c14n instance.
|
188
|
+
*/
|
189
|
+
public final String getURI() {
|
190
|
+
return canonicalizerSpi.engineGetURI();
|
191
|
+
}
|
192
|
+
|
193
|
+
/**
|
194
|
+
* Method getIncludeComments
|
195
|
+
*
|
196
|
+
* @return true if the c14n respect the comments.
|
197
|
+
*/
|
198
|
+
public boolean getIncludeComments() {
|
199
|
+
return canonicalizerSpi.engineGetIncludeComments();
|
200
|
+
}
|
201
|
+
|
202
|
+
/**
|
203
|
+
* Canonicalizes the subtree rooted by <CODE>node</CODE>.
|
204
|
+
*
|
205
|
+
* @param node The node to canonicalize
|
206
|
+
* @return the result of the c14n.
|
207
|
+
*
|
208
|
+
* @throws CanonicalizationException
|
209
|
+
*/
|
210
|
+
public byte[] canonicalizeSubtree(Node node, CanonicalFilter filter) throws CanonicalizationException {
|
211
|
+
return canonicalizerSpi.engineCanonicalizeSubTree(node, filter);
|
212
|
+
}
|
213
|
+
|
214
|
+
/**
|
215
|
+
* Canonicalizes the subtree rooted by <CODE>node</CODE>.
|
216
|
+
*
|
217
|
+
* @param node
|
218
|
+
* @param inclusiveNamespaces
|
219
|
+
* @return the result of the c14n.
|
220
|
+
* @throws CanonicalizationException
|
221
|
+
*/
|
222
|
+
public byte[] canonicalizeSubtree(Node node, String inclusiveNamespaces, CanonicalFilter filter)
|
223
|
+
throws CanonicalizationException {
|
224
|
+
return canonicalizerSpi.engineCanonicalizeSubTree(node, inclusiveNamespaces, filter);
|
225
|
+
}
|
226
|
+
|
227
|
+
/**
|
228
|
+
* Sets the writer where the canonicalization ends. ByteArrayOutputStream
|
229
|
+
* if none is set.
|
230
|
+
* @param os
|
231
|
+
*/
|
232
|
+
public void setWriter(OutputStream os) {
|
233
|
+
canonicalizerSpi.setWriter(os);
|
234
|
+
}
|
235
|
+
|
236
|
+
/**
|
237
|
+
* Returns the name of the implementing {@link CanonicalizerSpi} class
|
238
|
+
*
|
239
|
+
* @return the name of the implementing {@link CanonicalizerSpi} class
|
240
|
+
*/
|
241
|
+
public String getImplementingCanonicalizerClass() {
|
242
|
+
return canonicalizerSpi.getClass().getName();
|
243
|
+
}
|
244
|
+
|
245
|
+
/**
|
246
|
+
* Set the canonicalizer behaviour to not reset.
|
247
|
+
*/
|
248
|
+
public void notReset() {
|
249
|
+
canonicalizerSpi.reset = false;
|
250
|
+
}
|
251
|
+
|
252
|
+
}
|