nokogiri 1.11.0.rc3-java → 1.11.4-java
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of nokogiri might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/Gemfile +3 -0
- data/LICENSE-DEPENDENCIES.md +1015 -947
- data/LICENSE.md +1 -1
- data/README.md +168 -91
- data/dependencies.yml +12 -12
- data/ext/java/nokogiri/EncodingHandler.java +76 -89
- data/ext/java/nokogiri/HtmlDocument.java +135 -144
- data/ext/java/nokogiri/HtmlElementDescription.java +102 -117
- data/ext/java/nokogiri/HtmlEntityLookup.java +33 -60
- data/ext/java/nokogiri/HtmlSaxParserContext.java +218 -222
- data/ext/java/nokogiri/HtmlSaxPushParser.java +162 -169
- data/ext/java/nokogiri/NokogiriService.java +595 -556
- data/ext/java/nokogiri/XmlAttr.java +118 -126
- data/ext/java/nokogiri/XmlAttributeDecl.java +95 -106
- data/ext/java/nokogiri/XmlCdata.java +35 -58
- data/ext/java/nokogiri/XmlComment.java +46 -67
- data/ext/java/nokogiri/XmlDocument.java +645 -572
- data/ext/java/nokogiri/XmlDocumentFragment.java +125 -137
- data/ext/java/nokogiri/XmlDtd.java +448 -414
- data/ext/java/nokogiri/XmlElement.java +23 -48
- data/ext/java/nokogiri/XmlElementContent.java +343 -316
- data/ext/java/nokogiri/XmlElementDecl.java +124 -125
- data/ext/java/nokogiri/XmlEntityDecl.java +119 -127
- data/ext/java/nokogiri/XmlEntityReference.java +49 -72
- data/ext/java/nokogiri/XmlNamespace.java +175 -175
- data/ext/java/nokogiri/XmlNode.java +1843 -1622
- data/ext/java/nokogiri/XmlNodeSet.java +361 -331
- data/ext/java/nokogiri/XmlProcessingInstruction.java +47 -69
- data/ext/java/nokogiri/XmlReader.java +513 -450
- data/ext/java/nokogiri/XmlRelaxng.java +89 -101
- data/ext/java/nokogiri/XmlSaxParserContext.java +328 -310
- data/ext/java/nokogiri/XmlSaxPushParser.java +227 -220
- data/ext/java/nokogiri/XmlSchema.java +335 -242
- data/ext/java/nokogiri/XmlSyntaxError.java +113 -119
- data/ext/java/nokogiri/XmlText.java +55 -76
- data/ext/java/nokogiri/XmlXpathContext.java +242 -210
- data/ext/java/nokogiri/XsltStylesheet.java +280 -269
- data/ext/java/nokogiri/internals/ClosedStreamException.java +5 -2
- data/ext/java/nokogiri/internals/HtmlDomParserContext.java +201 -190
- data/ext/java/nokogiri/internals/IgnoreSchemaErrorsErrorHandler.java +17 -10
- data/ext/java/nokogiri/internals/NokogiriBlockingQueueInputStream.java +43 -16
- data/ext/java/nokogiri/internals/NokogiriDomParser.java +63 -80
- data/ext/java/nokogiri/internals/NokogiriEntityResolver.java +107 -88
- data/ext/java/nokogiri/internals/NokogiriErrorHandler.java +27 -52
- data/ext/java/nokogiri/internals/NokogiriHandler.java +316 -286
- data/ext/java/nokogiri/internals/NokogiriHelpers.java +736 -652
- data/ext/java/nokogiri/internals/NokogiriNamespaceCache.java +184 -173
- data/ext/java/nokogiri/internals/NokogiriNamespaceContext.java +79 -89
- data/ext/java/nokogiri/internals/NokogiriNonStrictErrorHandler.java +64 -79
- data/ext/java/nokogiri/internals/NokogiriNonStrictErrorHandler4NekoHtml.java +84 -99
- data/ext/java/nokogiri/internals/NokogiriStrictErrorHandler.java +48 -65
- data/ext/java/nokogiri/internals/NokogiriXPathFunction.java +119 -78
- data/ext/java/nokogiri/internals/NokogiriXPathFunctionResolver.java +34 -54
- data/ext/java/nokogiri/internals/NokogiriXPathVariableResolver.java +23 -46
- data/ext/java/nokogiri/internals/NokogiriXsltErrorListener.java +55 -72
- data/ext/java/nokogiri/internals/ParserContext.java +206 -211
- data/ext/java/nokogiri/internals/ReaderNode.java +478 -403
- data/ext/java/nokogiri/internals/SaveContextVisitor.java +822 -739
- data/ext/java/nokogiri/internals/SchemaErrorHandler.java +31 -54
- data/ext/java/nokogiri/internals/XalanDTMManagerPatch.java +129 -123
- data/ext/java/nokogiri/internals/XmlDeclHandler.java +3 -34
- data/ext/java/nokogiri/internals/XmlDomParserContext.java +206 -207
- data/ext/java/nokogiri/internals/XmlSaxParser.java +22 -47
- data/ext/java/nokogiri/internals/c14n/AttrCompare.java +71 -68
- data/ext/java/nokogiri/internals/c14n/C14nHelper.java +137 -118
- data/ext/java/nokogiri/internals/c14n/CanonicalFilter.java +27 -21
- data/ext/java/nokogiri/internals/c14n/CanonicalizationException.java +74 -61
- data/ext/java/nokogiri/internals/c14n/Canonicalizer.java +230 -205
- data/ext/java/nokogiri/internals/c14n/Canonicalizer11.java +572 -547
- data/ext/java/nokogiri/internals/c14n/Canonicalizer11_OmitComments.java +17 -10
- data/ext/java/nokogiri/internals/c14n/Canonicalizer11_WithComments.java +17 -10
- data/ext/java/nokogiri/internals/c14n/Canonicalizer20010315.java +323 -302
- data/ext/java/nokogiri/internals/c14n/Canonicalizer20010315Excl.java +232 -219
- data/ext/java/nokogiri/internals/c14n/Canonicalizer20010315ExclOmitComments.java +22 -15
- data/ext/java/nokogiri/internals/c14n/Canonicalizer20010315ExclWithComments.java +23 -16
- data/ext/java/nokogiri/internals/c14n/Canonicalizer20010315OmitComments.java +23 -16
- data/ext/java/nokogiri/internals/c14n/Canonicalizer20010315WithComments.java +22 -15
- data/ext/java/nokogiri/internals/c14n/CanonicalizerBase.java +575 -545
- data/ext/java/nokogiri/internals/c14n/CanonicalizerPhysical.java +141 -120
- data/ext/java/nokogiri/internals/c14n/CanonicalizerSpi.java +39 -38
- data/ext/java/nokogiri/internals/c14n/Constants.java +13 -10
- data/ext/java/nokogiri/internals/c14n/ElementProxy.java +279 -247
- data/ext/java/nokogiri/internals/c14n/HelperNodeList.java +66 -53
- data/ext/java/nokogiri/internals/c14n/IgnoreAllErrorHandler.java +44 -37
- data/ext/java/nokogiri/internals/c14n/InclusiveNamespaces.java +135 -120
- data/ext/java/nokogiri/internals/c14n/InvalidCanonicalizerException.java +59 -48
- data/ext/java/nokogiri/internals/c14n/NameSpaceSymbTable.java +384 -334
- data/ext/java/nokogiri/internals/c14n/NodeFilter.java +25 -24
- data/ext/java/nokogiri/internals/c14n/UtfHelpper.java +151 -140
- data/ext/java/nokogiri/internals/c14n/XMLUtils.java +456 -423
- data/ext/java/nokogiri/internals/dom2dtm/DOM2DTM.java +1466 -1500
- data/ext/java/nokogiri/internals/dom2dtm/DOM2DTMdefaultNamespaceDeclarationNode.java +626 -574
- data/ext/nokogiri/depend +37 -358
- data/ext/nokogiri/extconf.rb +581 -374
- data/ext/nokogiri/html_document.c +78 -82
- data/ext/nokogiri/html_element_description.c +84 -71
- data/ext/nokogiri/html_entity_lookup.c +21 -16
- data/ext/nokogiri/html_sax_parser_context.c +69 -66
- data/ext/nokogiri/html_sax_push_parser.c +42 -34
- data/ext/nokogiri/libxml2_backwards_compat.c +121 -0
- data/ext/nokogiri/nokogiri.c +192 -93
- data/ext/nokogiri/test_global_handlers.c +40 -0
- data/ext/nokogiri/xml_attr.c +15 -15
- data/ext/nokogiri/xml_attribute_decl.c +18 -18
- data/ext/nokogiri/xml_cdata.c +13 -18
- data/ext/nokogiri/xml_comment.c +19 -26
- data/ext/nokogiri/xml_document.c +246 -188
- data/ext/nokogiri/xml_document_fragment.c +13 -15
- data/ext/nokogiri/xml_dtd.c +54 -48
- data/ext/nokogiri/xml_element_content.c +30 -27
- data/ext/nokogiri/xml_element_decl.c +22 -22
- data/ext/nokogiri/xml_encoding_handler.c +17 -11
- data/ext/nokogiri/xml_entity_decl.c +32 -30
- data/ext/nokogiri/xml_entity_reference.c +16 -18
- data/ext/nokogiri/xml_namespace.c +56 -49
- data/ext/nokogiri/xml_node.c +371 -320
- data/ext/nokogiri/xml_node_set.c +168 -156
- data/ext/nokogiri/xml_processing_instruction.c +17 -19
- data/ext/nokogiri/xml_reader.c +191 -157
- data/ext/nokogiri/xml_relax_ng.c +52 -28
- data/ext/nokogiri/xml_sax_parser.c +118 -118
- data/ext/nokogiri/xml_sax_parser_context.c +103 -86
- data/ext/nokogiri/xml_sax_push_parser.c +36 -27
- data/ext/nokogiri/xml_schema.c +95 -47
- data/ext/nokogiri/xml_syntax_error.c +42 -21
- data/ext/nokogiri/xml_text.c +13 -17
- data/ext/nokogiri/xml_xpath_context.c +206 -123
- data/ext/nokogiri/xslt_stylesheet.c +158 -161
- data/lib/nokogiri.rb +3 -7
- data/lib/nokogiri/css/parser.rb +3 -3
- data/lib/nokogiri/css/parser.y +2 -2
- data/lib/nokogiri/css/xpath_visitor.rb +70 -42
- data/lib/nokogiri/extension.rb +26 -0
- data/lib/nokogiri/html/document.rb +12 -26
- data/lib/nokogiri/html/document_fragment.rb +15 -15
- data/lib/nokogiri/nokogiri.jar +0 -0
- data/lib/nokogiri/version.rb +2 -149
- data/lib/nokogiri/version/constant.rb +5 -0
- data/lib/nokogiri/version/info.rb +205 -0
- data/lib/nokogiri/xml/document.rb +91 -35
- data/lib/nokogiri/xml/document_fragment.rb +4 -6
- data/lib/nokogiri/xml/node.rb +89 -69
- data/lib/nokogiri/xml/parse_options.rb +6 -0
- data/lib/nokogiri/xml/reader.rb +2 -9
- data/lib/nokogiri/xml/relax_ng.rb +6 -2
- data/lib/nokogiri/xml/schema.rb +12 -4
- data/lib/nokogiri/xml/searchable.rb +3 -1
- data/lib/nokogiri/xml/xpath.rb +1 -3
- data/lib/nokogiri/xml/xpath/syntax_error.rb +1 -1
- metadata +86 -177
- data/ext/nokogiri/html_document.h +0 -10
- data/ext/nokogiri/html_element_description.h +0 -10
- data/ext/nokogiri/html_entity_lookup.h +0 -8
- data/ext/nokogiri/html_sax_parser_context.h +0 -11
- data/ext/nokogiri/html_sax_push_parser.h +0 -9
- data/ext/nokogiri/nokogiri.h +0 -134
- data/ext/nokogiri/xml_attr.h +0 -9
- data/ext/nokogiri/xml_attribute_decl.h +0 -9
- data/ext/nokogiri/xml_cdata.h +0 -9
- data/ext/nokogiri/xml_comment.h +0 -9
- data/ext/nokogiri/xml_document.h +0 -23
- data/ext/nokogiri/xml_document_fragment.h +0 -10
- data/ext/nokogiri/xml_dtd.h +0 -10
- data/ext/nokogiri/xml_element_content.h +0 -10
- data/ext/nokogiri/xml_element_decl.h +0 -9
- data/ext/nokogiri/xml_encoding_handler.h +0 -8
- data/ext/nokogiri/xml_entity_decl.h +0 -10
- data/ext/nokogiri/xml_entity_reference.h +0 -9
- data/ext/nokogiri/xml_io.c +0 -63
- data/ext/nokogiri/xml_io.h +0 -11
- data/ext/nokogiri/xml_libxml2_hacks.c +0 -112
- data/ext/nokogiri/xml_libxml2_hacks.h +0 -12
- data/ext/nokogiri/xml_namespace.h +0 -14
- data/ext/nokogiri/xml_node.h +0 -13
- data/ext/nokogiri/xml_node_set.h +0 -12
- data/ext/nokogiri/xml_processing_instruction.h +0 -9
- data/ext/nokogiri/xml_reader.h +0 -10
- data/ext/nokogiri/xml_relax_ng.h +0 -9
- data/ext/nokogiri/xml_sax_parser.h +0 -39
- data/ext/nokogiri/xml_sax_parser_context.h +0 -10
- data/ext/nokogiri/xml_sax_push_parser.h +0 -9
- data/ext/nokogiri/xml_schema.h +0 -9
- data/ext/nokogiri/xml_syntax_error.h +0 -13
- data/ext/nokogiri/xml_text.h +0 -9
- data/ext/nokogiri/xml_xpath_context.h +0 -10
- data/ext/nokogiri/xslt_stylesheet.h +0 -14
@@ -8,30 +8,36 @@ import org.jruby.runtime.ThreadContext;
|
|
8
8
|
import org.jruby.runtime.builtin.IRubyObject;
|
9
9
|
import org.w3c.dom.Node;
|
10
10
|
|
11
|
-
public class CanonicalFilter
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
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;
|
18
28
|
}
|
19
29
|
|
20
|
-
|
21
|
-
|
22
|
-
return true;
|
23
|
-
|
24
|
-
IRubyObject current = NokogiriHelpers.getCachedNodeOrCreate(context.getRuntime(), currentNode);
|
25
|
-
IRubyObject parent = NokogiriHelpers.getCachedNodeOrCreate(context.getRuntime(), parentNode);
|
30
|
+
IRubyObject current = NokogiriHelpers.getCachedNodeOrCreate(context.getRuntime(), currentNode);
|
31
|
+
IRubyObject parent = NokogiriHelpers.getCachedNodeOrCreate(context.getRuntime(), parentNode);
|
26
32
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
}
|
33
|
-
|
34
|
-
return block.call(context, current, parent).isTrue();
|
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;
|
35
38
|
}
|
36
39
|
|
40
|
+
return block.call(context, current, parent).isTrue();
|
41
|
+
}
|
42
|
+
|
37
43
|
}
|
@@ -24,70 +24,83 @@ package nokogiri.internals.c14n;
|
|
24
24
|
*
|
25
25
|
* @author Christian Geuer-Pollmann
|
26
26
|
*/
|
27
|
-
public class CanonicalizationException extends Exception
|
27
|
+
public class CanonicalizationException extends Exception
|
28
|
+
{
|
28
29
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
30
|
+
/**
|
31
|
+
*
|
32
|
+
*/
|
33
|
+
private static final long serialVersionUID = 1L;
|
33
34
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
35
|
+
/**
|
36
|
+
* Constructor CanonicalizationException
|
37
|
+
*
|
38
|
+
*/
|
39
|
+
public
|
40
|
+
CanonicalizationException()
|
41
|
+
{
|
42
|
+
super();
|
43
|
+
}
|
41
44
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
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
|
+
}
|
60
104
|
|
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
105
|
|
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
106
|
}
|
@@ -28,225 +28,250 @@ import org.w3c.dom.Node;
|
|
28
28
|
*
|
29
29
|
* @author Christian Geuer-Pollmann
|
30
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
|
-
}
|
31
|
+
public class Canonicalizer
|
32
|
+
{
|
103
33
|
|
104
|
-
|
105
|
-
|
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
|
-
}
|
34
|
+
/** The output encoding of canonicalized data */
|
35
|
+
public static final String ENCODING = "UTF8";
|
119
36
|
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
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
|
-
}
|
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::*)";
|
143
43
|
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
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";
|
163
79
|
|
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
|
-
}
|
80
|
+
private static Map<String, Class<? extends CanonicalizerSpi>> canonicalizerHash = null;
|
183
81
|
|
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
|
-
}
|
82
|
+
private final CanonicalizerSpi canonicalizerSpi;
|
192
83
|
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
84
|
+
/**
|
85
|
+
* Constructor Canonicalizer
|
86
|
+
*
|
87
|
+
* @param algorithmURI
|
88
|
+
* @throws InvalidCanonicalizerException
|
89
|
+
*/
|
90
|
+
private
|
91
|
+
Canonicalizer(String algorithmURI) throws CanonicalizationException
|
92
|
+
{
|
93
|
+
try {
|
94
|
+
Class<? extends CanonicalizerSpi> implementingClass =
|
95
|
+
canonicalizerHash.get(algorithmURI);
|
201
96
|
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
*/
|
210
|
-
public byte[] canonicalizeSubtree(Node node, CanonicalFilter filter) throws CanonicalizationException {
|
211
|
-
return canonicalizerSpi.engineCanonicalizeSubTree(node, filter);
|
97
|
+
canonicalizerSpi = implementingClass.newInstance();
|
98
|
+
canonicalizerSpi.reset = true;
|
99
|
+
} catch (Exception e) {
|
100
|
+
Object exArgs[] = { algorithmURI };
|
101
|
+
throw new CanonicalizationException(
|
102
|
+
"signature.Canonicalizer.UnknownCanonicalizer", exArgs, e
|
103
|
+
);
|
212
104
|
}
|
105
|
+
}
|
213
106
|
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
107
|
+
/**
|
108
|
+
* Method getInstance
|
109
|
+
*
|
110
|
+
* @param algorithmURI
|
111
|
+
* @return a Canonicalizer instance ready for the job
|
112
|
+
* @throws InvalidCanonicalizerException
|
113
|
+
*/
|
114
|
+
public static final Canonicalizer
|
115
|
+
getInstance(String algorithmURI)
|
116
|
+
throws CanonicalizationException
|
117
|
+
{
|
118
|
+
if (canonicalizerHash == null) {
|
119
|
+
canonicalizerHash = new ConcurrentHashMap<String, Class<? extends CanonicalizerSpi>>();
|
120
|
+
Canonicalizer.registerDefaultAlgorithms();
|
225
121
|
}
|
122
|
+
return new Canonicalizer(algorithmURI);
|
123
|
+
}
|
226
124
|
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
125
|
+
/**
|
126
|
+
* Method register
|
127
|
+
*
|
128
|
+
* @param algorithmURI
|
129
|
+
* @param implementingClass
|
130
|
+
* @throws CanonicalizationException
|
131
|
+
*/
|
132
|
+
@SuppressWarnings("unchecked")
|
133
|
+
public static void
|
134
|
+
register(String algorithmURI, String implementingClass)
|
135
|
+
throws CanonicalizationException, ClassNotFoundException
|
136
|
+
{
|
137
|
+
// check whether URI is already registered
|
138
|
+
Class<? extends CanonicalizerSpi> registeredClass =
|
139
|
+
canonicalizerHash.get(algorithmURI);
|
235
140
|
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
* @return the name of the implementing {@link CanonicalizerSpi} class
|
240
|
-
*/
|
241
|
-
public String getImplementingCanonicalizerClass() {
|
242
|
-
return canonicalizerSpi.getClass().getName();
|
141
|
+
if (registeredClass != null) {
|
142
|
+
Object exArgs[] = { algorithmURI, registeredClass };
|
143
|
+
throw new CanonicalizationException("algorithm.alreadyRegistered", exArgs);
|
243
144
|
}
|
244
145
|
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
146
|
+
canonicalizerHash.put(
|
147
|
+
algorithmURI, (Class<? extends CanonicalizerSpi>)Class.forName(implementingClass)
|
148
|
+
);
|
149
|
+
}
|
150
|
+
|
151
|
+
/**
|
152
|
+
* Method register
|
153
|
+
*
|
154
|
+
* @param algorithmURI
|
155
|
+
* @param implementingClass
|
156
|
+
* @throws CanonicalizationException
|
157
|
+
*/
|
158
|
+
public static void
|
159
|
+
register(String algorithmURI, Class<? extends CanonicalizerSpi> implementingClass)
|
160
|
+
throws CanonicalizationException
|
161
|
+
{
|
162
|
+
// check whether URI is already registered
|
163
|
+
Class<? extends CanonicalizerSpi> registeredClass = canonicalizerHash.get(algorithmURI);
|
164
|
+
|
165
|
+
if (registeredClass != null) {
|
166
|
+
Object exArgs[] = { algorithmURI, registeredClass };
|
167
|
+
throw new CanonicalizationException("algorithm.alreadyRegistered", exArgs);
|
250
168
|
}
|
251
169
|
|
170
|
+
canonicalizerHash.put(algorithmURI, implementingClass);
|
171
|
+
}
|
172
|
+
|
173
|
+
/**
|
174
|
+
* This method registers the default algorithms.
|
175
|
+
*/
|
176
|
+
private static void
|
177
|
+
registerDefaultAlgorithms()
|
178
|
+
{
|
179
|
+
canonicalizerHash.put(Canonicalizer.ALGO_ID_C14N_OMIT_COMMENTS,
|
180
|
+
Canonicalizer20010315OmitComments.class);
|
181
|
+
canonicalizerHash.put(Canonicalizer.ALGO_ID_C14N_WITH_COMMENTS,
|
182
|
+
Canonicalizer20010315WithComments.class);
|
183
|
+
canonicalizerHash.put(Canonicalizer.ALGO_ID_C14N_EXCL_OMIT_COMMENTS,
|
184
|
+
Canonicalizer20010315ExclOmitComments.class);
|
185
|
+
canonicalizerHash.put(Canonicalizer.ALGO_ID_C14N_EXCL_WITH_COMMENTS,
|
186
|
+
Canonicalizer20010315ExclWithComments.class);
|
187
|
+
canonicalizerHash.put(Canonicalizer.ALGO_ID_C14N11_OMIT_COMMENTS,
|
188
|
+
Canonicalizer11_OmitComments.class);
|
189
|
+
canonicalizerHash.put(Canonicalizer.ALGO_ID_C14N11_WITH_COMMENTS,
|
190
|
+
Canonicalizer11_WithComments.class);
|
191
|
+
canonicalizerHash.put(Canonicalizer.ALGO_ID_C14N_PHYSICAL,
|
192
|
+
CanonicalizerPhysical.class);
|
193
|
+
}
|
194
|
+
|
195
|
+
/**
|
196
|
+
* Method getURI
|
197
|
+
*
|
198
|
+
* @return the URI defined for this c14n instance.
|
199
|
+
*/
|
200
|
+
public final String
|
201
|
+
getURI()
|
202
|
+
{
|
203
|
+
return canonicalizerSpi.engineGetURI();
|
204
|
+
}
|
205
|
+
|
206
|
+
/**
|
207
|
+
* Method getIncludeComments
|
208
|
+
*
|
209
|
+
* @return true if the c14n respect the comments.
|
210
|
+
*/
|
211
|
+
public boolean
|
212
|
+
getIncludeComments()
|
213
|
+
{
|
214
|
+
return canonicalizerSpi.engineGetIncludeComments();
|
215
|
+
}
|
216
|
+
|
217
|
+
/**
|
218
|
+
* Canonicalizes the subtree rooted by <CODE>node</CODE>.
|
219
|
+
*
|
220
|
+
* @param node The node to canonicalize
|
221
|
+
* @return the result of the c14n.
|
222
|
+
*
|
223
|
+
* @throws CanonicalizationException
|
224
|
+
*/
|
225
|
+
public byte[]
|
226
|
+
canonicalizeSubtree(Node node, CanonicalFilter filter) throws CanonicalizationException
|
227
|
+
{
|
228
|
+
return canonicalizerSpi.engineCanonicalizeSubTree(node, filter);
|
229
|
+
}
|
230
|
+
|
231
|
+
/**
|
232
|
+
* Canonicalizes the subtree rooted by <CODE>node</CODE>.
|
233
|
+
*
|
234
|
+
* @param node
|
235
|
+
* @param inclusiveNamespaces
|
236
|
+
* @return the result of the c14n.
|
237
|
+
* @throws CanonicalizationException
|
238
|
+
*/
|
239
|
+
public byte[]
|
240
|
+
canonicalizeSubtree(Node node, String inclusiveNamespaces, CanonicalFilter filter)
|
241
|
+
throws CanonicalizationException
|
242
|
+
{
|
243
|
+
return canonicalizerSpi.engineCanonicalizeSubTree(node, inclusiveNamespaces, filter);
|
244
|
+
}
|
245
|
+
|
246
|
+
/**
|
247
|
+
* Sets the writer where the canonicalization ends. ByteArrayOutputStream
|
248
|
+
* if none is set.
|
249
|
+
* @param os
|
250
|
+
*/
|
251
|
+
public void
|
252
|
+
setWriter(OutputStream os)
|
253
|
+
{
|
254
|
+
canonicalizerSpi.setWriter(os);
|
255
|
+
}
|
256
|
+
|
257
|
+
/**
|
258
|
+
* Returns the name of the implementing {@link CanonicalizerSpi} class
|
259
|
+
*
|
260
|
+
* @return the name of the implementing {@link CanonicalizerSpi} class
|
261
|
+
*/
|
262
|
+
public String
|
263
|
+
getImplementingCanonicalizerClass()
|
264
|
+
{
|
265
|
+
return canonicalizerSpi.getClass().getName();
|
266
|
+
}
|
267
|
+
|
268
|
+
/**
|
269
|
+
* Set the canonicalizer behaviour to not reset.
|
270
|
+
*/
|
271
|
+
public void
|
272
|
+
notReset()
|
273
|
+
{
|
274
|
+
canonicalizerSpi.reset = false;
|
275
|
+
}
|
276
|
+
|
252
277
|
}
|