nokogiri 1.11.1-java → 1.11.6-java

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of nokogiri might be problematic. Click here for more details.

Files changed (143) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE-DEPENDENCIES.md +12 -12
  3. data/LICENSE.md +1 -1
  4. data/README.md +21 -16
  5. data/dependencies.yml +12 -12
  6. data/ext/java/nokogiri/EncodingHandler.java +76 -89
  7. data/ext/java/nokogiri/HtmlDocument.java +135 -144
  8. data/ext/java/nokogiri/HtmlElementDescription.java +102 -117
  9. data/ext/java/nokogiri/HtmlEntityLookup.java +33 -60
  10. data/ext/java/nokogiri/HtmlSaxParserContext.java +218 -222
  11. data/ext/java/nokogiri/HtmlSaxPushParser.java +162 -169
  12. data/ext/java/nokogiri/NokogiriService.java +595 -556
  13. data/ext/java/nokogiri/XmlAttr.java +118 -126
  14. data/ext/java/nokogiri/XmlAttributeDecl.java +95 -106
  15. data/ext/java/nokogiri/XmlCdata.java +35 -58
  16. data/ext/java/nokogiri/XmlComment.java +46 -67
  17. data/ext/java/nokogiri/XmlDocument.java +645 -572
  18. data/ext/java/nokogiri/XmlDocumentFragment.java +125 -137
  19. data/ext/java/nokogiri/XmlDtd.java +448 -414
  20. data/ext/java/nokogiri/XmlElement.java +23 -48
  21. data/ext/java/nokogiri/XmlElementContent.java +343 -316
  22. data/ext/java/nokogiri/XmlElementDecl.java +124 -125
  23. data/ext/java/nokogiri/XmlEntityDecl.java +119 -127
  24. data/ext/java/nokogiri/XmlEntityReference.java +49 -72
  25. data/ext/java/nokogiri/XmlNamespace.java +175 -175
  26. data/ext/java/nokogiri/XmlNode.java +1843 -1620
  27. data/ext/java/nokogiri/XmlNodeSet.java +361 -331
  28. data/ext/java/nokogiri/XmlProcessingInstruction.java +47 -69
  29. data/ext/java/nokogiri/XmlReader.java +513 -450
  30. data/ext/java/nokogiri/XmlRelaxng.java +85 -104
  31. data/ext/java/nokogiri/XmlSaxParserContext.java +328 -315
  32. data/ext/java/nokogiri/XmlSaxPushParser.java +227 -220
  33. data/ext/java/nokogiri/XmlSchema.java +328 -295
  34. data/ext/java/nokogiri/XmlSyntaxError.java +113 -115
  35. data/ext/java/nokogiri/XmlText.java +55 -76
  36. data/ext/java/nokogiri/XmlXpathContext.java +240 -238
  37. data/ext/java/nokogiri/XsltStylesheet.java +280 -269
  38. data/ext/java/nokogiri/internals/ClosedStreamException.java +5 -2
  39. data/ext/java/nokogiri/internals/HtmlDomParserContext.java +201 -202
  40. data/ext/java/nokogiri/internals/IgnoreSchemaErrorsErrorHandler.java +17 -10
  41. data/ext/java/nokogiri/internals/NokogiriBlockingQueueInputStream.java +43 -16
  42. data/ext/java/nokogiri/internals/NokogiriDomParser.java +63 -80
  43. data/ext/java/nokogiri/internals/NokogiriEntityResolver.java +107 -88
  44. data/ext/java/nokogiri/internals/NokogiriErrorHandler.java +27 -52
  45. data/ext/java/nokogiri/internals/NokogiriHandler.java +316 -286
  46. data/ext/java/nokogiri/internals/NokogiriHelpers.java +736 -652
  47. data/ext/java/nokogiri/internals/NokogiriNamespaceCache.java +184 -173
  48. data/ext/java/nokogiri/internals/NokogiriNamespaceContext.java +81 -98
  49. data/ext/java/nokogiri/internals/NokogiriNonStrictErrorHandler.java +64 -79
  50. data/ext/java/nokogiri/internals/NokogiriNonStrictErrorHandler4NekoHtml.java +84 -99
  51. data/ext/java/nokogiri/internals/NokogiriStrictErrorHandler.java +48 -65
  52. data/ext/java/nokogiri/internals/NokogiriXPathFunction.java +116 -131
  53. data/ext/java/nokogiri/internals/NokogiriXPathFunctionResolver.java +34 -56
  54. data/ext/java/nokogiri/internals/NokogiriXPathVariableResolver.java +23 -46
  55. data/ext/java/nokogiri/internals/NokogiriXsltErrorListener.java +55 -72
  56. data/ext/java/nokogiri/internals/ParserContext.java +206 -211
  57. data/ext/java/nokogiri/internals/ReaderNode.java +478 -403
  58. data/ext/java/nokogiri/internals/SaveContextVisitor.java +822 -739
  59. data/ext/java/nokogiri/internals/SchemaErrorHandler.java +31 -54
  60. data/ext/java/nokogiri/internals/XalanDTMManagerPatch.java +129 -123
  61. data/ext/java/nokogiri/internals/XmlDeclHandler.java +3 -34
  62. data/ext/java/nokogiri/internals/XmlDomParserContext.java +206 -207
  63. data/ext/java/nokogiri/internals/XmlSaxParser.java +22 -47
  64. data/ext/java/nokogiri/internals/c14n/AttrCompare.java +71 -68
  65. data/ext/java/nokogiri/internals/c14n/C14nHelper.java +137 -118
  66. data/ext/java/nokogiri/internals/c14n/CanonicalFilter.java +27 -21
  67. data/ext/java/nokogiri/internals/c14n/CanonicalizationException.java +74 -61
  68. data/ext/java/nokogiri/internals/c14n/Canonicalizer.java +230 -205
  69. data/ext/java/nokogiri/internals/c14n/Canonicalizer11.java +572 -547
  70. data/ext/java/nokogiri/internals/c14n/Canonicalizer11_OmitComments.java +17 -10
  71. data/ext/java/nokogiri/internals/c14n/Canonicalizer11_WithComments.java +17 -10
  72. data/ext/java/nokogiri/internals/c14n/Canonicalizer20010315.java +323 -302
  73. data/ext/java/nokogiri/internals/c14n/Canonicalizer20010315Excl.java +232 -219
  74. data/ext/java/nokogiri/internals/c14n/Canonicalizer20010315ExclOmitComments.java +22 -15
  75. data/ext/java/nokogiri/internals/c14n/Canonicalizer20010315ExclWithComments.java +23 -16
  76. data/ext/java/nokogiri/internals/c14n/Canonicalizer20010315OmitComments.java +23 -16
  77. data/ext/java/nokogiri/internals/c14n/Canonicalizer20010315WithComments.java +22 -15
  78. data/ext/java/nokogiri/internals/c14n/CanonicalizerBase.java +575 -545
  79. data/ext/java/nokogiri/internals/c14n/CanonicalizerPhysical.java +141 -120
  80. data/ext/java/nokogiri/internals/c14n/CanonicalizerSpi.java +39 -38
  81. data/ext/java/nokogiri/internals/c14n/Constants.java +13 -10
  82. data/ext/java/nokogiri/internals/c14n/ElementProxy.java +279 -247
  83. data/ext/java/nokogiri/internals/c14n/HelperNodeList.java +66 -53
  84. data/ext/java/nokogiri/internals/c14n/IgnoreAllErrorHandler.java +44 -37
  85. data/ext/java/nokogiri/internals/c14n/InclusiveNamespaces.java +135 -120
  86. data/ext/java/nokogiri/internals/c14n/InvalidCanonicalizerException.java +59 -48
  87. data/ext/java/nokogiri/internals/c14n/NameSpaceSymbTable.java +384 -334
  88. data/ext/java/nokogiri/internals/c14n/NodeFilter.java +25 -24
  89. data/ext/java/nokogiri/internals/c14n/UtfHelpper.java +151 -140
  90. data/ext/java/nokogiri/internals/c14n/XMLUtils.java +456 -423
  91. data/ext/java/nokogiri/internals/dom2dtm/DOM2DTM.java +1466 -1500
  92. data/ext/java/nokogiri/internals/dom2dtm/DOM2DTMdefaultNamespaceDeclarationNode.java +626 -574
  93. data/ext/nokogiri/depend +34 -474
  94. data/ext/nokogiri/extconf.rb +253 -183
  95. data/ext/nokogiri/html_document.c +10 -15
  96. data/ext/nokogiri/html_element_description.c +84 -71
  97. data/ext/nokogiri/html_entity_lookup.c +21 -16
  98. data/ext/nokogiri/html_sax_parser_context.c +66 -65
  99. data/ext/nokogiri/html_sax_push_parser.c +29 -27
  100. data/ext/nokogiri/libxml2_backwards_compat.c +121 -0
  101. data/ext/nokogiri/nokogiri.c +190 -63
  102. data/ext/nokogiri/test_global_handlers.c +3 -4
  103. data/ext/nokogiri/xml_attr.c +15 -15
  104. data/ext/nokogiri/xml_attribute_decl.c +18 -18
  105. data/ext/nokogiri/xml_cdata.c +13 -18
  106. data/ext/nokogiri/xml_comment.c +19 -26
  107. data/ext/nokogiri/xml_document.c +246 -188
  108. data/ext/nokogiri/xml_document_fragment.c +13 -15
  109. data/ext/nokogiri/xml_dtd.c +54 -48
  110. data/ext/nokogiri/xml_element_content.c +30 -27
  111. data/ext/nokogiri/xml_element_decl.c +22 -22
  112. data/ext/nokogiri/xml_encoding_handler.c +17 -11
  113. data/ext/nokogiri/xml_entity_decl.c +32 -30
  114. data/ext/nokogiri/xml_entity_reference.c +16 -18
  115. data/ext/nokogiri/xml_namespace.c +56 -49
  116. data/ext/nokogiri/xml_node.c +385 -326
  117. data/ext/nokogiri/xml_node_set.c +168 -156
  118. data/ext/nokogiri/xml_processing_instruction.c +17 -19
  119. data/ext/nokogiri/xml_reader.c +191 -157
  120. data/ext/nokogiri/xml_relax_ng.c +29 -23
  121. data/ext/nokogiri/xml_sax_parser.c +117 -112
  122. data/ext/nokogiri/xml_sax_parser_context.c +100 -85
  123. data/ext/nokogiri/xml_sax_push_parser.c +34 -27
  124. data/ext/nokogiri/xml_schema.c +48 -42
  125. data/ext/nokogiri/xml_syntax_error.c +21 -23
  126. data/ext/nokogiri/xml_text.c +13 -17
  127. data/ext/nokogiri/xml_xpath_context.c +134 -127
  128. data/ext/nokogiri/xslt_stylesheet.c +157 -157
  129. data/lib/nokogiri.rb +1 -22
  130. data/lib/nokogiri/css/parser.rb +1 -1
  131. data/lib/nokogiri/extension.rb +26 -0
  132. data/lib/nokogiri/html/document_fragment.rb +15 -15
  133. data/lib/nokogiri/nokogiri.jar +0 -0
  134. data/lib/nokogiri/version/constant.rb +1 -1
  135. data/lib/nokogiri/version/info.rb +32 -8
  136. data/lib/nokogiri/xml/document.rb +74 -28
  137. data/lib/nokogiri/xml/node.rb +39 -42
  138. data/lib/nokogiri/xml/reader.rb +2 -9
  139. data/lib/nokogiri/xml/xpath.rb +1 -3
  140. data/lib/nokogiri/xml/xpath/syntax_error.rb +1 -1
  141. metadata +7 -8
  142. data/ext/nokogiri/xml_io.c +0 -63
  143. data/ext/nokogiri/xml_libxml2_hacks.c +0 -112
@@ -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
- 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;
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
- 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);
30
+ IRubyObject current = NokogiriHelpers.getCachedNodeOrCreate(context.getRuntime(), currentNode);
31
+ IRubyObject parent = NokogiriHelpers.getCachedNodeOrCreate(context.getRuntime(), parentNode);
26
32
 
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();
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
- private static final long serialVersionUID = 1L;
30
+ /**
31
+ *
32
+ */
33
+ private static final long serialVersionUID = 1L;
33
34
 
34
- /**
35
- * Constructor CanonicalizationException
36
- *
37
- */
38
- public CanonicalizationException() {
39
- super();
40
- }
35
+ /**
36
+ * Constructor CanonicalizationException
37
+ *
38
+ */
39
+ public
40
+ CanonicalizationException()
41
+ {
42
+ super();
43
+ }
41
44
 
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
- }
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
- * 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
- }
34
+ /** The output encoding of canonicalized data */
35
+ public static final String ENCODING = "UTF8";
119
36
 
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
- }
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
- * 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
- }
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
- * Method getIncludeComments
195
- *
196
- * @return true if the c14n respect the comments.
197
- */
198
- public boolean getIncludeComments() {
199
- return canonicalizerSpi.engineGetIncludeComments();
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
- * 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);
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
- * 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);
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
- * 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
- }
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
- * 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();
141
+ if (registeredClass != null) {
142
+ Object exArgs[] = { algorithmURI, registeredClass };
143
+ throw new CanonicalizationException("algorithm.alreadyRegistered", exArgs);
243
144
  }
244
145
 
245
- /**
246
- * Set the canonicalizer behaviour to not reset.
247
- */
248
- public void notReset() {
249
- canonicalizerSpi.reset = false;
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
  }