Nokogiri_precompiled_aarch64_dedshit 1.14.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Gemfile +44 -0
- data/LICENSE-DEPENDENCIES.md +2224 -0
- data/LICENSE.md +9 -0
- data/README.md +287 -0
- data/bin/nokogiri +131 -0
- data/dependencies.yml +41 -0
- data/ext/java/nokogiri/Html4Document.java +157 -0
- data/ext/java/nokogiri/Html4ElementDescription.java +133 -0
- data/ext/java/nokogiri/Html4EntityLookup.java +63 -0
- data/ext/java/nokogiri/Html4SaxParserContext.java +289 -0
- data/ext/java/nokogiri/Html4SaxPushParser.java +213 -0
- data/ext/java/nokogiri/NokogiriService.java +613 -0
- data/ext/java/nokogiri/XmlAttr.java +154 -0
- data/ext/java/nokogiri/XmlAttributeDecl.java +119 -0
- data/ext/java/nokogiri/XmlCdata.java +60 -0
- data/ext/java/nokogiri/XmlComment.java +77 -0
- data/ext/java/nokogiri/XmlDocument.java +705 -0
- data/ext/java/nokogiri/XmlDocumentFragment.java +163 -0
- data/ext/java/nokogiri/XmlDtd.java +516 -0
- data/ext/java/nokogiri/XmlElement.java +44 -0
- data/ext/java/nokogiri/XmlElementContent.java +412 -0
- data/ext/java/nokogiri/XmlElementDecl.java +148 -0
- data/ext/java/nokogiri/XmlEntityDecl.java +151 -0
- data/ext/java/nokogiri/XmlEntityReference.java +79 -0
- data/ext/java/nokogiri/XmlNamespace.java +193 -0
- data/ext/java/nokogiri/XmlNode.java +1938 -0
- data/ext/java/nokogiri/XmlNodeSet.java +463 -0
- data/ext/java/nokogiri/XmlProcessingInstruction.java +79 -0
- data/ext/java/nokogiri/XmlReader.java +615 -0
- data/ext/java/nokogiri/XmlRelaxng.java +133 -0
- data/ext/java/nokogiri/XmlSaxParserContext.java +329 -0
- data/ext/java/nokogiri/XmlSaxPushParser.java +288 -0
- data/ext/java/nokogiri/XmlSchema.java +423 -0
- data/ext/java/nokogiri/XmlSyntaxError.java +137 -0
- data/ext/java/nokogiri/XmlText.java +90 -0
- data/ext/java/nokogiri/XmlXpathContext.java +305 -0
- data/ext/java/nokogiri/XsltStylesheet.java +368 -0
- data/ext/java/nokogiri/internals/ClosedStreamException.java +13 -0
- data/ext/java/nokogiri/internals/HtmlDomParserContext.java +252 -0
- data/ext/java/nokogiri/internals/IgnoreSchemaErrorsErrorHandler.java +27 -0
- data/ext/java/nokogiri/internals/NokogiriBlockingQueueInputStream.java +178 -0
- data/ext/java/nokogiri/internals/NokogiriDomParser.java +99 -0
- data/ext/java/nokogiri/internals/NokogiriEntityResolver.java +140 -0
- data/ext/java/nokogiri/internals/NokogiriErrorHandler.java +65 -0
- data/ext/java/nokogiri/internals/NokogiriHandler.java +339 -0
- data/ext/java/nokogiri/internals/NokogiriHelpers.java +817 -0
- data/ext/java/nokogiri/internals/NokogiriNamespaceCache.java +228 -0
- data/ext/java/nokogiri/internals/NokogiriNamespaceContext.java +110 -0
- data/ext/java/nokogiri/internals/NokogiriNonStrictErrorHandler.java +86 -0
- data/ext/java/nokogiri/internals/NokogiriNonStrictErrorHandler4NekoHtml.java +107 -0
- data/ext/java/nokogiri/internals/NokogiriStrictErrorHandler.java +62 -0
- data/ext/java/nokogiri/internals/NokogiriXPathFunction.java +165 -0
- data/ext/java/nokogiri/internals/NokogiriXPathFunctionResolver.java +50 -0
- data/ext/java/nokogiri/internals/NokogiriXPathVariableResolver.java +37 -0
- data/ext/java/nokogiri/internals/NokogiriXsltErrorListener.java +70 -0
- data/ext/java/nokogiri/internals/ParserContext.java +262 -0
- data/ext/java/nokogiri/internals/ReaderNode.java +564 -0
- data/ext/java/nokogiri/internals/SaveContextVisitor.java +865 -0
- data/ext/java/nokogiri/internals/SchemaErrorHandler.java +50 -0
- data/ext/java/nokogiri/internals/XalanDTMManagerPatch.java +174 -0
- data/ext/java/nokogiri/internals/XmlDeclHandler.java +11 -0
- data/ext/java/nokogiri/internals/XmlDomParserContext.java +265 -0
- data/ext/java/nokogiri/internals/XmlSaxParser.java +40 -0
- data/ext/java/nokogiri/internals/c14n/AttrCompare.java +122 -0
- data/ext/java/nokogiri/internals/c14n/C14nHelper.java +178 -0
- data/ext/java/nokogiri/internals/c14n/CanonicalFilter.java +43 -0
- data/ext/java/nokogiri/internals/c14n/CanonicalizationException.java +106 -0
- data/ext/java/nokogiri/internals/c14n/Canonicalizer.java +278 -0
- data/ext/java/nokogiri/internals/c14n/Canonicalizer11.java +664 -0
- data/ext/java/nokogiri/internals/c14n/Canonicalizer11_OmitComments.java +45 -0
- data/ext/java/nokogiri/internals/c14n/Canonicalizer11_WithComments.java +45 -0
- data/ext/java/nokogiri/internals/c14n/Canonicalizer20010315.java +388 -0
- data/ext/java/nokogiri/internals/c14n/Canonicalizer20010315Excl.java +308 -0
- data/ext/java/nokogiri/internals/c14n/Canonicalizer20010315ExclOmitComments.java +47 -0
- data/ext/java/nokogiri/internals/c14n/Canonicalizer20010315ExclWithComments.java +51 -0
- data/ext/java/nokogiri/internals/c14n/Canonicalizer20010315OmitComments.java +51 -0
- data/ext/java/nokogiri/internals/c14n/Canonicalizer20010315WithComments.java +50 -0
- data/ext/java/nokogiri/internals/c14n/CanonicalizerBase.java +660 -0
- data/ext/java/nokogiri/internals/c14n/CanonicalizerPhysical.java +194 -0
- data/ext/java/nokogiri/internals/c14n/CanonicalizerSpi.java +77 -0
- data/ext/java/nokogiri/internals/c14n/Constants.java +45 -0
- data/ext/java/nokogiri/internals/c14n/ElementProxy.java +325 -0
- data/ext/java/nokogiri/internals/c14n/HelperNodeList.java +106 -0
- data/ext/java/nokogiri/internals/c14n/IgnoreAllErrorHandler.java +86 -0
- data/ext/java/nokogiri/internals/c14n/InclusiveNamespaces.java +181 -0
- data/ext/java/nokogiri/internals/c14n/InvalidCanonicalizerException.java +87 -0
- data/ext/java/nokogiri/internals/c14n/NameSpaceSymbTable.java +452 -0
- data/ext/java/nokogiri/internals/c14n/NodeFilter.java +52 -0
- data/ext/java/nokogiri/internals/c14n/UtfHelpper.java +190 -0
- data/ext/java/nokogiri/internals/c14n/XMLUtils.java +540 -0
- data/ext/java/nokogiri/internals/dom2dtm/DOM2DTM.java +1712 -0
- data/ext/java/nokogiri/internals/dom2dtm/DOM2DTMdefaultNamespaceDeclarationNode.java +737 -0
- data/ext/nokogiri/depend +38 -0
- data/ext/nokogiri/extconf.rb +1086 -0
- data/ext/nokogiri/gumbo.c +594 -0
- data/ext/nokogiri/html4_document.c +167 -0
- data/ext/nokogiri/html4_element_description.c +294 -0
- data/ext/nokogiri/html4_entity_lookup.c +37 -0
- data/ext/nokogiri/html4_sax_parser_context.c +116 -0
- data/ext/nokogiri/html4_sax_push_parser.c +95 -0
- data/ext/nokogiri/libxml2_backwards_compat.c +121 -0
- data/ext/nokogiri/nokogiri.c +265 -0
- data/ext/nokogiri/nokogiri.h +235 -0
- data/ext/nokogiri/test_global_handlers.c +42 -0
- data/ext/nokogiri/xml_attr.c +103 -0
- data/ext/nokogiri/xml_attribute_decl.c +70 -0
- data/ext/nokogiri/xml_cdata.c +57 -0
- data/ext/nokogiri/xml_comment.c +62 -0
- data/ext/nokogiri/xml_document.c +689 -0
- data/ext/nokogiri/xml_document_fragment.c +44 -0
- data/ext/nokogiri/xml_dtd.c +210 -0
- data/ext/nokogiri/xml_element_content.c +128 -0
- data/ext/nokogiri/xml_element_decl.c +69 -0
- data/ext/nokogiri/xml_encoding_handler.c +104 -0
- data/ext/nokogiri/xml_entity_decl.c +112 -0
- data/ext/nokogiri/xml_entity_reference.c +50 -0
- data/ext/nokogiri/xml_namespace.c +186 -0
- data/ext/nokogiri/xml_node.c +2426 -0
- data/ext/nokogiri/xml_node_set.c +496 -0
- data/ext/nokogiri/xml_processing_instruction.c +54 -0
- data/ext/nokogiri/xml_reader.c +794 -0
- data/ext/nokogiri/xml_relax_ng.c +164 -0
- data/ext/nokogiri/xml_sax_parser.c +316 -0
- data/ext/nokogiri/xml_sax_parser_context.c +283 -0
- data/ext/nokogiri/xml_sax_push_parser.c +166 -0
- data/ext/nokogiri/xml_schema.c +260 -0
- data/ext/nokogiri/xml_syntax_error.c +85 -0
- data/ext/nokogiri/xml_text.c +48 -0
- data/ext/nokogiri/xml_xpath_context.c +415 -0
- data/ext/nokogiri/xslt_stylesheet.c +363 -0
- data/gumbo-parser/CHANGES.md +63 -0
- data/gumbo-parser/Makefile +111 -0
- data/gumbo-parser/THANKS +27 -0
- data/gumbo-parser/src/Makefile +34 -0
- data/gumbo-parser/src/README.md +41 -0
- data/gumbo-parser/src/ascii.c +75 -0
- data/gumbo-parser/src/ascii.h +115 -0
- data/gumbo-parser/src/attribute.c +42 -0
- data/gumbo-parser/src/attribute.h +17 -0
- data/gumbo-parser/src/char_ref.c +22225 -0
- data/gumbo-parser/src/char_ref.h +29 -0
- data/gumbo-parser/src/char_ref.rl +2154 -0
- data/gumbo-parser/src/error.c +626 -0
- data/gumbo-parser/src/error.h +148 -0
- data/gumbo-parser/src/foreign_attrs.c +104 -0
- data/gumbo-parser/src/foreign_attrs.gperf +27 -0
- data/gumbo-parser/src/insertion_mode.h +33 -0
- data/gumbo-parser/src/macros.h +91 -0
- data/gumbo-parser/src/nokogiri_gumbo.h +944 -0
- data/gumbo-parser/src/parser.c +4878 -0
- data/gumbo-parser/src/parser.h +41 -0
- data/gumbo-parser/src/replacement.h +33 -0
- data/gumbo-parser/src/string_buffer.c +103 -0
- data/gumbo-parser/src/string_buffer.h +68 -0
- data/gumbo-parser/src/string_piece.c +48 -0
- data/gumbo-parser/src/svg_attrs.c +174 -0
- data/gumbo-parser/src/svg_attrs.gperf +77 -0
- data/gumbo-parser/src/svg_tags.c +137 -0
- data/gumbo-parser/src/svg_tags.gperf +55 -0
- data/gumbo-parser/src/tag.c +223 -0
- data/gumbo-parser/src/tag_lookup.c +382 -0
- data/gumbo-parser/src/tag_lookup.gperf +170 -0
- data/gumbo-parser/src/tag_lookup.h +13 -0
- data/gumbo-parser/src/token_buffer.c +79 -0
- data/gumbo-parser/src/token_buffer.h +71 -0
- data/gumbo-parser/src/token_type.h +17 -0
- data/gumbo-parser/src/tokenizer.c +3463 -0
- data/gumbo-parser/src/tokenizer.h +112 -0
- data/gumbo-parser/src/tokenizer_states.h +339 -0
- data/gumbo-parser/src/utf8.c +245 -0
- data/gumbo-parser/src/utf8.h +164 -0
- data/gumbo-parser/src/util.c +66 -0
- data/gumbo-parser/src/util.h +34 -0
- data/gumbo-parser/src/vector.c +111 -0
- data/gumbo-parser/src/vector.h +45 -0
- data/lib/nokogiri/class_resolver.rb +67 -0
- data/lib/nokogiri/css/node.rb +54 -0
- data/lib/nokogiri/css/parser.rb +770 -0
- data/lib/nokogiri/css/parser.y +277 -0
- data/lib/nokogiri/css/parser_extras.rb +96 -0
- data/lib/nokogiri/css/syntax_error.rb +9 -0
- data/lib/nokogiri/css/tokenizer.rb +155 -0
- data/lib/nokogiri/css/tokenizer.rex +56 -0
- data/lib/nokogiri/css/xpath_visitor.rb +359 -0
- data/lib/nokogiri/css.rb +66 -0
- data/lib/nokogiri/decorators/slop.rb +44 -0
- data/lib/nokogiri/encoding_handler.rb +57 -0
- data/lib/nokogiri/extension.rb +32 -0
- data/lib/nokogiri/gumbo.rb +15 -0
- data/lib/nokogiri/html.rb +48 -0
- data/lib/nokogiri/html4/builder.rb +37 -0
- data/lib/nokogiri/html4/document.rb +214 -0
- data/lib/nokogiri/html4/document_fragment.rb +54 -0
- data/lib/nokogiri/html4/element_description.rb +25 -0
- data/lib/nokogiri/html4/element_description_defaults.rb +572 -0
- data/lib/nokogiri/html4/encoding_reader.rb +121 -0
- data/lib/nokogiri/html4/entity_lookup.rb +15 -0
- data/lib/nokogiri/html4/sax/parser.rb +63 -0
- data/lib/nokogiri/html4/sax/parser_context.rb +20 -0
- data/lib/nokogiri/html4/sax/push_parser.rb +37 -0
- data/lib/nokogiri/html4.rb +47 -0
- data/lib/nokogiri/html5/document.rb +168 -0
- data/lib/nokogiri/html5/document_fragment.rb +90 -0
- data/lib/nokogiri/html5/node.rb +98 -0
- data/lib/nokogiri/html5.rb +389 -0
- data/lib/nokogiri/jruby/dependencies.rb +3 -0
- data/lib/nokogiri/jruby/isorelax/isorelax/20030108/isorelax-20030108.jar +0 -0
- data/lib/nokogiri/jruby/net/sf/saxon/Saxon-HE/9.6.0-4/Saxon-HE-9.6.0-4.jar +0 -0
- data/lib/nokogiri/jruby/net/sourceforge/htmlunit/neko-htmlunit/2.63.0/neko-htmlunit-2.63.0.jar +0 -0
- data/lib/nokogiri/jruby/nokogiri_jars.rb +43 -0
- data/lib/nokogiri/jruby/nu/validator/jing/20200702VNU/jing-20200702VNU.jar +0 -0
- data/lib/nokogiri/jruby/org/nokogiri/nekodtd/0.1.11.noko2/nekodtd-0.1.11.noko2.jar +0 -0
- data/lib/nokogiri/jruby/xalan/serializer/2.7.3/serializer-2.7.3.jar +0 -0
- data/lib/nokogiri/jruby/xalan/xalan/2.7.3/xalan-2.7.3.jar +0 -0
- data/lib/nokogiri/jruby/xerces/xercesImpl/2.12.2/xercesImpl-2.12.2.jar +0 -0
- data/lib/nokogiri/jruby/xml-apis/xml-apis/1.4.01/xml-apis-1.4.01.jar +0 -0
- data/lib/nokogiri/syntax_error.rb +6 -0
- data/lib/nokogiri/version/constant.rb +6 -0
- data/lib/nokogiri/version/info.rb +223 -0
- data/lib/nokogiri/version.rb +4 -0
- data/lib/nokogiri/xml/attr.rb +66 -0
- data/lib/nokogiri/xml/attribute_decl.rb +20 -0
- data/lib/nokogiri/xml/builder.rb +487 -0
- data/lib/nokogiri/xml/cdata.rb +13 -0
- data/lib/nokogiri/xml/character_data.rb +9 -0
- data/lib/nokogiri/xml/document.rb +471 -0
- data/lib/nokogiri/xml/document_fragment.rb +205 -0
- data/lib/nokogiri/xml/dtd.rb +34 -0
- data/lib/nokogiri/xml/element_content.rb +38 -0
- data/lib/nokogiri/xml/element_decl.rb +15 -0
- data/lib/nokogiri/xml/entity_decl.rb +21 -0
- data/lib/nokogiri/xml/entity_reference.rb +20 -0
- data/lib/nokogiri/xml/namespace.rb +58 -0
- data/lib/nokogiri/xml/node/save_options.rb +68 -0
- data/lib/nokogiri/xml/node.rb +1563 -0
- data/lib/nokogiri/xml/node_set.rb +447 -0
- data/lib/nokogiri/xml/notation.rb +19 -0
- data/lib/nokogiri/xml/parse_options.rb +213 -0
- data/lib/nokogiri/xml/pp/character_data.rb +21 -0
- data/lib/nokogiri/xml/pp/node.rb +57 -0
- data/lib/nokogiri/xml/pp.rb +4 -0
- data/lib/nokogiri/xml/processing_instruction.rb +11 -0
- data/lib/nokogiri/xml/reader.rb +105 -0
- data/lib/nokogiri/xml/relax_ng.rb +38 -0
- data/lib/nokogiri/xml/sax/document.rb +167 -0
- data/lib/nokogiri/xml/sax/parser.rb +125 -0
- data/lib/nokogiri/xml/sax/parser_context.rb +21 -0
- data/lib/nokogiri/xml/sax/push_parser.rb +61 -0
- data/lib/nokogiri/xml/sax.rb +6 -0
- data/lib/nokogiri/xml/schema.rb +73 -0
- data/lib/nokogiri/xml/searchable.rb +270 -0
- data/lib/nokogiri/xml/syntax_error.rb +72 -0
- data/lib/nokogiri/xml/text.rb +11 -0
- data/lib/nokogiri/xml/xpath/syntax_error.rb +13 -0
- data/lib/nokogiri/xml/xpath.rb +21 -0
- data/lib/nokogiri/xml/xpath_context.rb +16 -0
- data/lib/nokogiri/xml.rb +76 -0
- data/lib/nokogiri/xslt/stylesheet.rb +27 -0
- data/lib/nokogiri/xslt.rb +65 -0
- data/lib/nokogiri.rb +120 -0
- data/lib/xsd/xmlparser/nokogiri.rb +106 -0
- metadata +391 -0
@@ -0,0 +1,178 @@
|
|
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
|
+
/**
|
36
|
+
* Constructor C14nHelper
|
37
|
+
*
|
38
|
+
*/
|
39
|
+
private
|
40
|
+
C14nHelper()
|
41
|
+
{
|
42
|
+
// don't allow instantiation
|
43
|
+
}
|
44
|
+
|
45
|
+
/**
|
46
|
+
* Method namespaceIsRelative
|
47
|
+
*
|
48
|
+
* @param namespace
|
49
|
+
* @return true if the given namespace is relative.
|
50
|
+
*/
|
51
|
+
public static boolean
|
52
|
+
namespaceIsRelative(Attr namespace)
|
53
|
+
{
|
54
|
+
return !namespaceIsAbsolute(namespace);
|
55
|
+
}
|
56
|
+
|
57
|
+
/**
|
58
|
+
* Method namespaceIsRelative
|
59
|
+
*
|
60
|
+
* @param namespaceValue
|
61
|
+
* @return true if the given namespace is relative.
|
62
|
+
*/
|
63
|
+
public static boolean
|
64
|
+
namespaceIsRelative(String namespaceValue)
|
65
|
+
{
|
66
|
+
return !namespaceIsAbsolute(namespaceValue);
|
67
|
+
}
|
68
|
+
|
69
|
+
/**
|
70
|
+
* Method namespaceIsAbsolute
|
71
|
+
*
|
72
|
+
* @param namespace
|
73
|
+
* @return true if the given namespace is absolute.
|
74
|
+
*/
|
75
|
+
public static boolean
|
76
|
+
namespaceIsAbsolute(Attr namespace)
|
77
|
+
{
|
78
|
+
return namespaceIsAbsolute(namespace.getValue());
|
79
|
+
}
|
80
|
+
|
81
|
+
/**
|
82
|
+
* Method namespaceIsAbsolute
|
83
|
+
*
|
84
|
+
* @param namespaceValue
|
85
|
+
* @return true if the given namespace is absolute.
|
86
|
+
*/
|
87
|
+
public static boolean
|
88
|
+
namespaceIsAbsolute(String namespaceValue)
|
89
|
+
{
|
90
|
+
// assume empty namespaces are absolute
|
91
|
+
if (namespaceValue.length() == 0) {
|
92
|
+
return true;
|
93
|
+
}
|
94
|
+
return namespaceValue.indexOf(':') > 0;
|
95
|
+
}
|
96
|
+
|
97
|
+
/**
|
98
|
+
* This method throws an exception if the Attribute value contains
|
99
|
+
* a relative URI.
|
100
|
+
*
|
101
|
+
* @param attr
|
102
|
+
* @throws CanonicalizationException
|
103
|
+
*/
|
104
|
+
public static void
|
105
|
+
assertNotRelativeNS(Attr attr) throws CanonicalizationException
|
106
|
+
{
|
107
|
+
if (attr == null) {
|
108
|
+
return;
|
109
|
+
}
|
110
|
+
|
111
|
+
String nodeAttrName = attr.getNodeName();
|
112
|
+
boolean definesDefaultNS = nodeAttrName.equals("xmlns");
|
113
|
+
boolean definesNonDefaultNS = nodeAttrName.startsWith("xmlns:");
|
114
|
+
|
115
|
+
if ((definesDefaultNS || definesNonDefaultNS) && namespaceIsRelative(attr)) {
|
116
|
+
String parentName = attr.getOwnerElement().getTagName();
|
117
|
+
String attrValue = attr.getValue();
|
118
|
+
Object exArgs[] = { parentName, nodeAttrName, attrValue };
|
119
|
+
|
120
|
+
throw new CanonicalizationException(
|
121
|
+
"c14n.Canonicalizer.RelativeNamespace", exArgs
|
122
|
+
);
|
123
|
+
}
|
124
|
+
}
|
125
|
+
|
126
|
+
/**
|
127
|
+
* This method throws a CanonicalizationException if the supplied Document
|
128
|
+
* is not able to be traversed using a TreeWalker.
|
129
|
+
*
|
130
|
+
* @param document
|
131
|
+
* @throws CanonicalizationException
|
132
|
+
*/
|
133
|
+
public static void
|
134
|
+
checkTraversability(Document document)
|
135
|
+
throws CanonicalizationException
|
136
|
+
{
|
137
|
+
if (!document.isSupported("Traversal", "2.0")) {
|
138
|
+
Object exArgs[] = {document.getImplementation().getClass().getName() };
|
139
|
+
|
140
|
+
throw new CanonicalizationException(
|
141
|
+
"c14n.Canonicalizer.TraversalNotSupported", exArgs
|
142
|
+
);
|
143
|
+
}
|
144
|
+
}
|
145
|
+
|
146
|
+
/**
|
147
|
+
* This method throws a CanonicalizationException if the supplied Element
|
148
|
+
* contains any relative namespaces.
|
149
|
+
*
|
150
|
+
* @param ctxNode
|
151
|
+
* @throws CanonicalizationException
|
152
|
+
* @see C14nHelper#assertNotRelativeNS(Attr)
|
153
|
+
*/
|
154
|
+
public static void
|
155
|
+
checkForRelativeNamespace(Element ctxNode)
|
156
|
+
throws CanonicalizationException
|
157
|
+
{
|
158
|
+
if (ctxNode != null) {
|
159
|
+
NamedNodeMap attributes = ctxNode.getAttributes();
|
160
|
+
|
161
|
+
for (int i = 0; i < attributes.getLength(); i++) {
|
162
|
+
C14nHelper.assertNotRelativeNS((Attr) attributes.item(i));
|
163
|
+
}
|
164
|
+
} else {
|
165
|
+
throw new CanonicalizationException("Called checkForRelativeNamespace() on null");
|
166
|
+
}
|
167
|
+
}
|
168
|
+
|
169
|
+
public static String
|
170
|
+
getErrorMessage(String message, Object... exArgs)
|
171
|
+
{
|
172
|
+
StringBuffer sb = new StringBuffer(message);
|
173
|
+
for (Object arg : exArgs) {
|
174
|
+
sb.append(", ").append(arg.toString());
|
175
|
+
}
|
176
|
+
return new String(sb);
|
177
|
+
}
|
178
|
+
}
|
@@ -0,0 +1,43 @@
|
|
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
|
+
{
|
13
|
+
private final Block block;
|
14
|
+
private final ThreadContext context;
|
15
|
+
|
16
|
+
public
|
17
|
+
CanonicalFilter(ThreadContext context, Block block)
|
18
|
+
{
|
19
|
+
this.context = context;
|
20
|
+
this.block = block;
|
21
|
+
}
|
22
|
+
|
23
|
+
public boolean
|
24
|
+
includeNodes(Node currentNode, Node parentNode)
|
25
|
+
{
|
26
|
+
if (block == null || !block.isGiven()) {
|
27
|
+
return true;
|
28
|
+
}
|
29
|
+
|
30
|
+
IRubyObject current = NokogiriHelpers.getCachedNodeOrCreate(context.getRuntime(), currentNode);
|
31
|
+
IRubyObject parent = NokogiriHelpers.getCachedNodeOrCreate(context.getRuntime(), parentNode);
|
32
|
+
|
33
|
+
if (parent.isNil()) {
|
34
|
+
IRubyObject doc = ((XmlNode) current).document(context);
|
35
|
+
boolean returnValue = block.call(context, current, doc).isTrue();
|
36
|
+
block.call(context, doc, context.nil);
|
37
|
+
return returnValue;
|
38
|
+
}
|
39
|
+
|
40
|
+
return block.call(context, current, parent).isTrue();
|
41
|
+
}
|
42
|
+
|
43
|
+
}
|
@@ -0,0 +1,106 @@
|
|
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
|
+
*/
|
33
|
+
private static final long serialVersionUID = 1L;
|
34
|
+
|
35
|
+
/**
|
36
|
+
* Constructor CanonicalizationException
|
37
|
+
*
|
38
|
+
*/
|
39
|
+
public
|
40
|
+
CanonicalizationException()
|
41
|
+
{
|
42
|
+
super();
|
43
|
+
}
|
44
|
+
|
45
|
+
/**
|
46
|
+
* Constructor CanonicalizationException
|
47
|
+
*
|
48
|
+
* @param message
|
49
|
+
*/
|
50
|
+
public
|
51
|
+
CanonicalizationException(String message)
|
52
|
+
{
|
53
|
+
super(message);
|
54
|
+
}
|
55
|
+
|
56
|
+
/**
|
57
|
+
* Constructor CanonicalizationException
|
58
|
+
*
|
59
|
+
* @param message
|
60
|
+
* @param rootCause
|
61
|
+
*/
|
62
|
+
public
|
63
|
+
CanonicalizationException(Exception rootCause)
|
64
|
+
{
|
65
|
+
super(rootCause);
|
66
|
+
}
|
67
|
+
|
68
|
+
/**
|
69
|
+
* Constructor CanonicalizationException
|
70
|
+
*
|
71
|
+
* @param msgID
|
72
|
+
* @param exArgs
|
73
|
+
*/
|
74
|
+
public
|
75
|
+
CanonicalizationException(String message, Object... exArgs)
|
76
|
+
{
|
77
|
+
super(C14nHelper.getErrorMessage(message, exArgs));
|
78
|
+
}
|
79
|
+
|
80
|
+
/**
|
81
|
+
* Constructor CanonicalizationException
|
82
|
+
*
|
83
|
+
* @param message
|
84
|
+
* @param rootCause
|
85
|
+
*/
|
86
|
+
public
|
87
|
+
CanonicalizationException(String message, Exception rootCause)
|
88
|
+
{
|
89
|
+
super(message, rootCause);
|
90
|
+
}
|
91
|
+
|
92
|
+
/**
|
93
|
+
* Constructor CanonicalizationException
|
94
|
+
*
|
95
|
+
* @param msgID
|
96
|
+
* @param exArgs
|
97
|
+
* @param originalException
|
98
|
+
*/
|
99
|
+
public
|
100
|
+
CanonicalizationException(String message, Exception rootCause, Object... exArgs)
|
101
|
+
{
|
102
|
+
super(C14nHelper.getErrorMessage(message, exArgs), rootCause);
|
103
|
+
}
|
104
|
+
|
105
|
+
|
106
|
+
}
|
@@ -0,0 +1,278 @@
|
|
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
|
+
|
34
|
+
/** The output encoding of canonicalized data */
|
35
|
+
public static final String ENCODING = "UTF8";
|
36
|
+
|
37
|
+
/**
|
38
|
+
* XPath Expression for selecting every node and continuous comments joined
|
39
|
+
* in only one node
|
40
|
+
*/
|
41
|
+
public static final String XPATH_C14N_WITH_COMMENTS_SINGLE_NODE =
|
42
|
+
"(.//. | .//@* | .//namespace::*)";
|
43
|
+
|
44
|
+
/**
|
45
|
+
* The URL defined in XML-SEC Rec for inclusive c14n <b>without</b> comments.
|
46
|
+
*/
|
47
|
+
public static final String ALGO_ID_C14N_OMIT_COMMENTS =
|
48
|
+
"http://www.w3.org/TR/2001/REC-xml-c14n-20010315";
|
49
|
+
/**
|
50
|
+
* The URL defined in XML-SEC Rec for inclusive c14n <b>with</b> comments.
|
51
|
+
*/
|
52
|
+
public static final String ALGO_ID_C14N_WITH_COMMENTS =
|
53
|
+
ALGO_ID_C14N_OMIT_COMMENTS + "#WithComments";
|
54
|
+
/**
|
55
|
+
* The URL defined in XML-SEC Rec for exclusive c14n <b>without</b> comments.
|
56
|
+
*/
|
57
|
+
public static final String ALGO_ID_C14N_EXCL_OMIT_COMMENTS =
|
58
|
+
"http://www.w3.org/2001/10/xml-exc-c14n#";
|
59
|
+
/**
|
60
|
+
* The URL defined in XML-SEC Rec for exclusive c14n <b>with</b> comments.
|
61
|
+
*/
|
62
|
+
public static final String ALGO_ID_C14N_EXCL_WITH_COMMENTS =
|
63
|
+
ALGO_ID_C14N_EXCL_OMIT_COMMENTS + "WithComments";
|
64
|
+
/**
|
65
|
+
* The URI for inclusive c14n 1.1 <b>without</b> comments.
|
66
|
+
*/
|
67
|
+
public static final String ALGO_ID_C14N11_OMIT_COMMENTS =
|
68
|
+
"http://www.w3.org/2006/12/xml-c14n11";
|
69
|
+
/**
|
70
|
+
* The URI for inclusive c14n 1.1 <b>with</b> comments.
|
71
|
+
*/
|
72
|
+
public static final String ALGO_ID_C14N11_WITH_COMMENTS =
|
73
|
+
ALGO_ID_C14N11_OMIT_COMMENTS + "#WithComments";
|
74
|
+
/**
|
75
|
+
* Non-standard algorithm to serialize the physical representation for XML Encryption
|
76
|
+
*/
|
77
|
+
public static final String ALGO_ID_C14N_PHYSICAL =
|
78
|
+
"http://santuario.apache.org/c14n/physical";
|
79
|
+
|
80
|
+
private static Map<String, Class<? extends CanonicalizerSpi>> canonicalizerHash = null;
|
81
|
+
|
82
|
+
private final CanonicalizerSpi canonicalizerSpi;
|
83
|
+
|
84
|
+
/**
|
85
|
+
* Constructor Canonicalizer
|
86
|
+
*
|
87
|
+
* @param algorithmURI
|
88
|
+
* @throws InvalidCanonicalizerException
|
89
|
+
*/
|
90
|
+
@SuppressWarnings("deprecation")
|
91
|
+
private
|
92
|
+
Canonicalizer(String algorithmURI) throws CanonicalizationException
|
93
|
+
{
|
94
|
+
try {
|
95
|
+
Class<? extends CanonicalizerSpi> implementingClass =
|
96
|
+
canonicalizerHash.get(algorithmURI);
|
97
|
+
|
98
|
+
canonicalizerSpi = implementingClass.newInstance();
|
99
|
+
canonicalizerSpi.reset = true;
|
100
|
+
} catch (Exception e) {
|
101
|
+
Object exArgs[] = { algorithmURI };
|
102
|
+
throw new CanonicalizationException(
|
103
|
+
"signature.Canonicalizer.UnknownCanonicalizer", exArgs, e
|
104
|
+
);
|
105
|
+
}
|
106
|
+
}
|
107
|
+
|
108
|
+
/**
|
109
|
+
* Method getInstance
|
110
|
+
*
|
111
|
+
* @param algorithmURI
|
112
|
+
* @return a Canonicalizer instance ready for the job
|
113
|
+
* @throws InvalidCanonicalizerException
|
114
|
+
*/
|
115
|
+
public static final Canonicalizer
|
116
|
+
getInstance(String algorithmURI)
|
117
|
+
throws CanonicalizationException
|
118
|
+
{
|
119
|
+
if (canonicalizerHash == null) {
|
120
|
+
canonicalizerHash = new ConcurrentHashMap<String, Class<? extends CanonicalizerSpi>>();
|
121
|
+
Canonicalizer.registerDefaultAlgorithms();
|
122
|
+
}
|
123
|
+
return new Canonicalizer(algorithmURI);
|
124
|
+
}
|
125
|
+
|
126
|
+
/**
|
127
|
+
* Method register
|
128
|
+
*
|
129
|
+
* @param algorithmURI
|
130
|
+
* @param implementingClass
|
131
|
+
* @throws CanonicalizationException
|
132
|
+
*/
|
133
|
+
@SuppressWarnings("unchecked")
|
134
|
+
public static void
|
135
|
+
register(String algorithmURI, String implementingClass)
|
136
|
+
throws CanonicalizationException, ClassNotFoundException
|
137
|
+
{
|
138
|
+
// check whether URI is already registered
|
139
|
+
Class<? extends CanonicalizerSpi> registeredClass =
|
140
|
+
canonicalizerHash.get(algorithmURI);
|
141
|
+
|
142
|
+
if (registeredClass != null) {
|
143
|
+
Object exArgs[] = { algorithmURI, registeredClass };
|
144
|
+
throw new CanonicalizationException("algorithm.alreadyRegistered", exArgs);
|
145
|
+
}
|
146
|
+
|
147
|
+
canonicalizerHash.put(
|
148
|
+
algorithmURI, (Class<? extends CanonicalizerSpi>)Class.forName(implementingClass)
|
149
|
+
);
|
150
|
+
}
|
151
|
+
|
152
|
+
/**
|
153
|
+
* Method register
|
154
|
+
*
|
155
|
+
* @param algorithmURI
|
156
|
+
* @param implementingClass
|
157
|
+
* @throws CanonicalizationException
|
158
|
+
*/
|
159
|
+
public static void
|
160
|
+
register(String algorithmURI, Class<? extends CanonicalizerSpi> implementingClass)
|
161
|
+
throws CanonicalizationException
|
162
|
+
{
|
163
|
+
// check whether URI is already registered
|
164
|
+
Class<? extends CanonicalizerSpi> registeredClass = canonicalizerHash.get(algorithmURI);
|
165
|
+
|
166
|
+
if (registeredClass != null) {
|
167
|
+
Object exArgs[] = { algorithmURI, registeredClass };
|
168
|
+
throw new CanonicalizationException("algorithm.alreadyRegistered", exArgs);
|
169
|
+
}
|
170
|
+
|
171
|
+
canonicalizerHash.put(algorithmURI, implementingClass);
|
172
|
+
}
|
173
|
+
|
174
|
+
/**
|
175
|
+
* This method registers the default algorithms.
|
176
|
+
*/
|
177
|
+
private static void
|
178
|
+
registerDefaultAlgorithms()
|
179
|
+
{
|
180
|
+
canonicalizerHash.put(Canonicalizer.ALGO_ID_C14N_OMIT_COMMENTS,
|
181
|
+
Canonicalizer20010315OmitComments.class);
|
182
|
+
canonicalizerHash.put(Canonicalizer.ALGO_ID_C14N_WITH_COMMENTS,
|
183
|
+
Canonicalizer20010315WithComments.class);
|
184
|
+
canonicalizerHash.put(Canonicalizer.ALGO_ID_C14N_EXCL_OMIT_COMMENTS,
|
185
|
+
Canonicalizer20010315ExclOmitComments.class);
|
186
|
+
canonicalizerHash.put(Canonicalizer.ALGO_ID_C14N_EXCL_WITH_COMMENTS,
|
187
|
+
Canonicalizer20010315ExclWithComments.class);
|
188
|
+
canonicalizerHash.put(Canonicalizer.ALGO_ID_C14N11_OMIT_COMMENTS,
|
189
|
+
Canonicalizer11_OmitComments.class);
|
190
|
+
canonicalizerHash.put(Canonicalizer.ALGO_ID_C14N11_WITH_COMMENTS,
|
191
|
+
Canonicalizer11_WithComments.class);
|
192
|
+
canonicalizerHash.put(Canonicalizer.ALGO_ID_C14N_PHYSICAL,
|
193
|
+
CanonicalizerPhysical.class);
|
194
|
+
}
|
195
|
+
|
196
|
+
/**
|
197
|
+
* Method getURI
|
198
|
+
*
|
199
|
+
* @return the URI defined for this c14n instance.
|
200
|
+
*/
|
201
|
+
public final String
|
202
|
+
getURI()
|
203
|
+
{
|
204
|
+
return canonicalizerSpi.engineGetURI();
|
205
|
+
}
|
206
|
+
|
207
|
+
/**
|
208
|
+
* Method getIncludeComments
|
209
|
+
*
|
210
|
+
* @return true if the c14n respect the comments.
|
211
|
+
*/
|
212
|
+
public boolean
|
213
|
+
getIncludeComments()
|
214
|
+
{
|
215
|
+
return canonicalizerSpi.engineGetIncludeComments();
|
216
|
+
}
|
217
|
+
|
218
|
+
/**
|
219
|
+
* Canonicalizes the subtree rooted by <CODE>node</CODE>.
|
220
|
+
*
|
221
|
+
* @param node The node to canonicalize
|
222
|
+
* @return the result of the c14n.
|
223
|
+
*
|
224
|
+
* @throws CanonicalizationException
|
225
|
+
*/
|
226
|
+
public byte[]
|
227
|
+
canonicalizeSubtree(Node node, CanonicalFilter filter) throws CanonicalizationException
|
228
|
+
{
|
229
|
+
return canonicalizerSpi.engineCanonicalizeSubTree(node, filter);
|
230
|
+
}
|
231
|
+
|
232
|
+
/**
|
233
|
+
* Canonicalizes the subtree rooted by <CODE>node</CODE>.
|
234
|
+
*
|
235
|
+
* @param node
|
236
|
+
* @param inclusiveNamespaces
|
237
|
+
* @return the result of the c14n.
|
238
|
+
* @throws CanonicalizationException
|
239
|
+
*/
|
240
|
+
public byte[]
|
241
|
+
canonicalizeSubtree(Node node, String inclusiveNamespaces, CanonicalFilter filter)
|
242
|
+
throws CanonicalizationException
|
243
|
+
{
|
244
|
+
return canonicalizerSpi.engineCanonicalizeSubTree(node, inclusiveNamespaces, filter);
|
245
|
+
}
|
246
|
+
|
247
|
+
/**
|
248
|
+
* Sets the writer where the canonicalization ends. ByteArrayOutputStream
|
249
|
+
* if none is set.
|
250
|
+
* @param os
|
251
|
+
*/
|
252
|
+
public void
|
253
|
+
setWriter(OutputStream os)
|
254
|
+
{
|
255
|
+
canonicalizerSpi.setWriter(os);
|
256
|
+
}
|
257
|
+
|
258
|
+
/**
|
259
|
+
* Returns the name of the implementing {@link CanonicalizerSpi} class
|
260
|
+
*
|
261
|
+
* @return the name of the implementing {@link CanonicalizerSpi} class
|
262
|
+
*/
|
263
|
+
public String
|
264
|
+
getImplementingCanonicalizerClass()
|
265
|
+
{
|
266
|
+
return canonicalizerSpi.getClass().getName();
|
267
|
+
}
|
268
|
+
|
269
|
+
/**
|
270
|
+
* Set the canonicalizer behaviour to not reset.
|
271
|
+
*/
|
272
|
+
public void
|
273
|
+
notReset()
|
274
|
+
{
|
275
|
+
canonicalizerSpi.reset = false;
|
276
|
+
}
|
277
|
+
|
278
|
+
}
|